Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate's generator class not really working?
    text
    copied!<p>Asking this question here after hours of frustration with me and my Eclipse. Hoping to find some respite here. </p> <p>I'm trying to save a pojo object into MySQL database via Hibernate 3.0. Basically my requirement is: I need to assign the id for the object before save and not let Hibernate do it for me.</p> <p>For this I looked up in the documentation and saw that <code>&lt;generator class="assigned"/&gt;</code> perfectly fits my bill. Consequently I updated by <code>.hbm.xml</code> file with the following for the <code>id</code>:</p> <pre><code>&lt;id name="id" type="int"&gt; &lt;column name="ID" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; </code></pre> <p>My pojo matches <code>.hbm.xml</code> file to the T.</p> <p>I'm setting all the parameters including the <code>ID</code> of my pojo and calling Hibernate's <code>saveOrUpdate(object)</code> method.</p> <p>If it's of any help, the <code>ID</code> column of my database table has "auto-inc" disabled.</p> <p>Unbelievably, when I look at the database table contents, a row has been inserted with Hibernate's own ID and not what I had set. </p> <p>How's it possible? Is there anything else affecting the <code>ID</code>? Am I missing on something? What's the work around?</p> <p>My <code>hibernate.properties</code> looks like below(if it's of any help):</p> <pre><code>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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload