<$BlogRSDURL$>

Sunday, February 29, 2004

Hibernate - ID unsaved-value 

Another lesson learnt.

If the java type of your primary key "id" is of a primitive type int, long, double, etc, the "unsaved-value" attribute must be filled with a value. For instance, if you declare your primary key in your model class as "private int key;", then your unsaved-value should be 0. If you declare your primary key as "private int key = -1;", then your unsaved-value should be -1;

Otherwise, you will get this error when you are trying to save or update the object, "Batch update row count wrong: 0..."

The above is also explained in the FAQ.

Thursday, February 26, 2004

JavaWorld - No more updated articles 

JavaWorld has announced that there will be no more updated articles. I am hoping that it is just a temporarily move.

Wednesday, February 18, 2004

Hibernate 2.1 - ehcache library required! 

Topic: DB Object Mapping

I just downloaded Hibernate 2.1.2 and was trying out the tutorial in the reference pdf file. As instructed, I copied the following to my webapp lib directory: cglib-2.0-rc2.jar, commons-collections-2.1.jar, commons-dbcp-1.1.jar, commons-lang-1.0.1.jar, commons-logging-1.0.3.jar, commons-pool-1.1.jar, dom4j-1.4.jar, hibernate2.jar, log4j-1.2.8.jar, odmg-3.0.jar. I must admit that I did not read the "Readme.txt" file in the lib directory of the hibernate distribution.

When I start my tomcat, the debug and info level log looks normal and there is nothing in my error log. However, my JSP throws "org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)". Seriously this exception message is not at all helpful. I have to insert more log4j statement all over the sample code "HibernateUtil". Finally, I found the following exception message thrown "could not instantiate CacheProvider: net.sf.ehcache.hibernate.Provider".

From a google search on the error message, it leads me back to the Hibernate FAQ which points out that the library "ehcache.jar" is needed from Hibernate 2.1 onwards. This really teach me a lesson to read the FAQ first. However, in the first place, the exception is not really logged properly, which could have left me clueless.

Friday, February 13, 2004

Comparison among various DB Object Mapping Tools 

Topic: DB Object Mapping

Found this site where someone makes some comparison on the various Object mapping tools.

Another Object Mapping tools - iBATIS 

Topic: DB Object Mapping

Came across another object-mapping tool called iBATIS. This tool is abit different as it maps JavaBeans to SQL statement instead of the table schemas.

For instance,
<mapped-statement name="getAddress"
result-class="examples.domain.Address">
select
ADR_ID as id,
ADR_DESCRIPTION as description,
ADR_STREET as street,
ADR_CITY as city,
ADR_PROVINCE as province,
ADR_POSTAL_CODE as postalCode
from ADDRESS
where ADR_ID = #value#
</mapped-statement>

This page is powered by Blogger. Isn't yours?