I'm new to Hibernate, so excuse the novice-ness.
I'm working with table that has a composite-id that is generated by the database. When I create a new object and persist it, the id in the object is not changed. How can I get the value generated for the two columns?
Mapping documents:
Drp1Node.hbm.xml
Code:
<hibernate-mapping>
<class name="model.Drp1Node" table="drp1_node" catalog="db9551_spin_drupal">
<composite-id name="id" class="model.Drp1NodeId">
<key-property name="nid" type="int">
<column name="nid" />
</key-property>
<key-property name="vid" type="int">
<column name="vid" />
</key-property>
</composite-id>
<property name="type" type="string">
<column name="type" length="32" not-null="true" />
</property>
<property name="title" type="string">
<column name="title" length="128" not-null="true" />
</property>
<property name="uid" type="int">
<column name="uid" not-null="true" />
</property>
<property name="status" type="int">
<column name="status" not-null="true" />
</property>
<property name="created" type="int">
<column name="created" not-null="true" />
</property>
<property name="changed" type="int">
<column name="changed" not-null="true" />
</property>
<property name="comment" type="int">
<column name="comment" not-null="true" />
</property>
<property name="promote" type="int">
<column name="promote" not-null="true" />
</property>
<property name="moderate" type="int">
<column name="moderate" not-null="true" />
</property>
<property name="sticky" type="int">
<column name="sticky" not-null="true" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Drp1NodeId newId = new Drp1NodeId();
System.out.println("id1: "+newId.getNid());
Drp1Node newNode = new Drp1Node();
newNode.setId(newId);
System.out.println("id2: "+newId.getNid() + "("+newNode.getId().getNid()+")");
Drp1NodeId savedId = (Drp1NodeId)HibernateUtil.save(newNode);
System.out.println("id3: "+newId.getNid() + "("+newNode.getId().getNid()+")");
HibernateUtil.getSessionFactory().getCurrentSession().flush();
System.out.println("id5: "+newId.getNid() + "("+newNode.getId().getNid()+")");
System.out
id1: 0
id2: 0(0)
id3: 0(0)
Hibernate: insert into db9551_spin_drupal.drp1_node (type, title, uid, status, created, changed, comment, promote, moderate, sticky, nid, vid) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
id5: 0(0)