Hibernate class generator not working?

Asking this question here after hours of disappointment with me and my Eclipse. Hope to find some respite here.

I am trying to save a pojo object in a MySQL database through Hibernate 3.0. Basically my requirement: I need to assign an id to the object before saving and not let Hibernate do this for me.

To do this, I looked through the documentation and saw that <generator class="assigned"/> great for my account. Therefore, I updated the .hbm.xml file as follows for id :

 <id name="id" type="int"> <column name="ID" /> <generator class="assigned" /> </id> 

My pojo maps the .hbm.xml file to T.

I set all the parameters, including the id my pojo and calling the Hibernate saveOrUpdate(object) method.

If any help, the id column in my database table has disabled "auto-inc".

Incredibly, when I look at the contents of the database table, the row was inserted with its own Hibernate identifier, and not what I set.

How is this possible? Does anything else affect id ? Did I miss something? What job?

My hibernate.properties looks below (if it has any help):

 hibernate.connection.driver_class =com.mysql.jdbc.Driver hibernate.dialect =org.hibernate.dialect.MySQLDialect hibernate.connection.url =jdbc:mysql://localhost/dbdbdbdbdb hibernate.connection.username=root hibernate.connection.password=password hibernate.connection.pool_size=10 jdbc.batch_size=30 hibernate.show_sql=true hibernate.current_session_context_class=true hibernate.hbm2ddl.auto=validate hibernate.cglib.use_reflection_optimizer=false hibernate.generate_statistics=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory 
+4
source share
2 answers

Well, hoax! It was really a problem with the integration of Eclipse - Tomcat . I had to clean Tomcat directories and republish before hbm files could take effect.

Tip. . If you run ant inside Eclipse, be sure to constantly update the Eclipse workspace. Learning some things the hard way.

+1
source

You can write your own sequence generator class to return identifiers matching your requirements. See http://danu-javastuff.blogspot.com/2009/01/custom-id-generator-class-for-hibernate.html for details

0
source

All Articles