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
source share