-->
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.  [ 2 posts ] 
Author Message
 Post subject: primary key of referred parent changed : Hibernate exception
PostPosted: Sun Nov 20, 2011 11:02 am 
Newbie

Joined: Mon May 09, 2011 1:06 am
Posts: 4
I have Student object which holds reference to ID of Address object.

I read the Student object and update the referred parent.
When I use unique non primary key from the referred/parent object I face no problems.

When my association refers to primary key and not unique key of parent then I face problems
Problem faced when Relationship mapped as

<many-to-one name="StudentAddress" name="com.san.Address" fetch="join" unique="true" update="true" insert="true" optimistic-lock="true" not-found="exception" embed-xml="true">
<column name="AddressID" not-null="true"/>
</many-to-one>

NO PROBLEM when:

<many-to-one name="StudentAddress" property-ref="UK_Address" name="com.san.Address" fetch="join" unique="true" update="true" insert="true" optimistic-lock="true" not-found="exception" embed-xml="true">
<column name="pinCode" not-null="true"/>
<column name="country" not-null="true"/>
</many-to-one>



my parent class is:
<class name="com.san.Address" table="Address" dynamic-insert="true" mutable="true" polymorphism="implicit" dynamic-update="false" select-before-update="false" optimistic-lock="version">
<id name="ID" type="java.lang.Long" column="ID">
<generator class="native"/>
</id>
<properties name="UK_Address" unique="true" update="true" insert="true" optimistic-lock="true">
<property name="PinCode" type="java.lang.Long" column="PinCode" unique="false" optimistic-lock="true" lazy="false" generated="never"/>
<property name="Country" type="java.lang.String" column="Country" unique="false" optimistic-lock="true" lazy="false" generated="never"/>
</properties>

</class>



Caused by:
org.hibernate.HibernateException: identifier of an instance of Address was a
ltered from 3 to 2
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(Defau
ltFlushEntityEventListener.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(Def
aultFlushEntityEventListener.java:164)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity
(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(A
bstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverything
ToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlus
hEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)


Top
 Profile  
 
 Post subject: Re: primary key of referred parent changed : Hibernate exception
PostPosted: Thu Nov 24, 2011 11:09 pm 
Newbie

Joined: Mon May 09, 2011 1:06 am
Posts: 4
This issue was resolved , by creating a new object of Address with the given id and replacing the object associated with object Student.


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

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.