Hi
I am trying to generate the Id from a single oracle sequence. Problem is the ID value generated by the hibernate query is different from the one saved in DB. e.g. If hibernate query generates the ID_SEQ.nextval = 22 for CustomerID the saved value for the same field is 23 in DB.
Interesting thing is when i save the Employee-Address-Contact relation it saves right IDs. When i do same for Customer-Address-Contact relation it generates different value for CustomerID.
Iam using Oracle10g, Hibernate3.2 and single ID_SEQ for all entities.
My mapping files are given as follow; Please suggest something as it stopping me to work ahead and i am new to this technology.
Employee
-----------
<hibernate-mapping>
<class
name="com.wonder.common.Employee"
table="EMPLOYEE">
<id
name="id"
type="long"
column="EMP_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="fName">
<column name="FIRST_NAME" />
</property>
<property name="lName">
<column name="LAST_NAME" />
</property>
...
<set
name="contact"
cascade="save-update,persist">
<key
column="EMP_ID"
not-null="true" />
<one-to-many
class="com.wonder.common.Contact"
entity-name="EmpContacts" />
</set>
<set
name="address"
table="EMP_ADDRESS"
cascade="save-update,persist">
<key column="EMP_ID" />
<many-to-many
column="ADDRESS_ID"
class="com.wonder.common.Address" />
</set>
</class>
Customer
------------
<class
name="com.wonder.common.Customer"
table="CUSTOMER"
dynamic-insert="true"
dynamic-update="true">
<id
name="id"
type="long"
column="CUST_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="fName">
<column name="FIRST_NAME" />
</property>
<property name="lName">
<column name="LAST_NAME" />
</property>
....
<set
name="contact"
cascade="save-update,persist">
<key
column="CUST_ID"
not-null="true" />
<one-to-many
class="com.wonder.common.Contact"
entity-name="CustContacts" />
</set>
<set
name="address"
table="CUST_ADDRESS"
cascade="save-update,persist">
<key
column="CUST_ID"
not-null="true" />
<many-to-many
column="ADDRESS_ID"
class="com.wonder.common.Address" />
</set>
</class>
contact
---------
<hibernate-mapping>
<class
name="com.wonder.common.Contact"
entity-name="EmpContacts"
table="EMP_CONTACT">
<id
name="id"
type="long"
column="CONTACT_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="homePhone">
<column name="HOME" />
</property>
<property name="officePhone">
<column name="OFFICE" />
</property>
...
</class>
<class
name="com.wonder.common.Contact"
entity-name="CustContacts"
table="CUST_CONTACT">
<id
name="id"
type="long"
column="CONTACT_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="homePhone">
<column name="HOME" />
</property>
<property name="officePhone">
<column name="OFFICE" />
</property>
...
</class>
address
---------
<hibernate-mapping>
<class
name="com.wonder.common.Address"
table="ADDRESS">
<id
name="id"
type="long"
column="ADDRESS_ID">
<generator class="sequence">
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<property name="Type">
<column name="TYPE" />
</property>
<property name="Street">
<column name="STREET" />
</property>
...
</class>
</hibernate-mapping>
_________________ Thanks in Advance
Kashif
|