-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ID Problem
PostPosted: Wed May 21, 2008 10:57 am 
Newbie

Joined: Mon May 12, 2008 12:16 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.