-->
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.  [ 10 posts ] 
Author Message
 Post subject: Exception
PostPosted: Fri Jul 20, 2007 6:40 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
Hi friends,

Plz help,
I am getting this exception during save in Hibernate.

Exception in thread "main" org.hibernate.HibernateException: identifier of an instance of EmplyeeDetails was altered from 2 to 0

My class name is "EmplyeeDetails"
Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 6:57 am 
Newbie

Joined: Thu Jul 19, 2007 11:43 pm
Posts: 2
Hi..
you are not giving enough info..
maybe you can paste the mapping file..
and the POJO involved..

but neverthless i try to explain what happen..

you get this error because you are trying to update the Primary Key of the Object..which is cannot be done..

if you do it purposely.. i tell u as far as i know.. Primary Key cannot be updated..

if you don't know what happen.. why hibernate try to update the primary key..
i have a couple of explanation..
1. You use primitive type (int,long etc) type, not Object (Integer,Long)as a Primary Key .. inside the pojo.. use object type instead (primitive type is not nullable, if not initialized the primitive type value will be 0)

2. If this case occur when you are trying to insert a record.. then the problem lies in your ID generation...



hope this helps,

give more info .. so we'll be sure whats wrong

elanhakim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:09 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
hi


Last edited by Nagendra Kumar on Fri Jul 20, 2007 7:10 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:09 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
HI i am sending pojo class and hbm.xml

Exception
==============
Hibernate: select max(id) from table1
Hibernate: select max(id) from table2
Exception in thread "main" org.hibernate.HibernateException: identifier of an instance of customeDetails was altered from 2 to 0
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at Main.main(Main.java:29)
========================================
pojo class

import java.util.*;
public class customeDetails
{
private Set stories ;
public customeDetails()
{
}
private Integer id =0;
public void setId(Integer id)
{
id = id ;
}
public Integer getId()
{
return id;
}
}
==============================================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="customeDetails" table="table1">
<id name="id" unsaved-value="0" >
<generator class="increment" />
</id>
<set name="stories" cascade="all" inverse="true">
<key column="parent_id"/>
<one-to-many class="TABLE2"/>
</set>
</class>

<class name="TABLE2" table="table2">
<id name="id" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="test" type="string"/>
<property name="results" type="string"/>
<many-to-one name="parent" column="parent_id" not-null="true"/>
</class>
</hibernate-mapping>

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:31 am 
Newbie

Joined: Wed Mar 21, 2007 3:42 am
Posts: 4
Location: Chennai
Hi

Please could you look at this following link.I think,it would be helpful for you.

http://jira.codehaus.org/browse/GRAILS-225

Thanks
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:31 am 
Newbie

Joined: Wed Mar 21, 2007 3:42 am
Posts: 4
Location: Chennai
Hi

Please could you look at this following link.I think,it would be helpful for you.

http://jira.codehaus.org/browse/GRAILS-225

Thanks
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:34 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

remove unsaved-value


Amila
(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 7:42 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
amila733 wrote:
Hi

remove unsaved-value


Amila
(Don't forget to rate if helps)


Hi,

I remove unsaved-value, but it throw same exception .
give some more idea.
Thanks in adv.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 8:22 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi
send your code which raised the error


Amila


Top
 Profile  
 
 Post subject: Problem solved
PostPosted: Fri Jul 20, 2007 8:31 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
Thanks friends,
Problem solved.
once again thanks 4 Suggestion .


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.