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.  [ 6 posts ] 
Author Message
 Post subject: identifier of an instance of Class was altered from 3 to 2
PostPosted: Mon Jan 28, 2008 5:35 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
I'm using Hibernate 3 with Microsoft SQL Server 2005. I have a a Geodetic class whose mapping file looks like this:

Code:
<hibernate-mapping package="dao.coordinate">
   <class name="Geodetic" table="CRD_Geodetic">
      <id name="id" column="id">
         <generator class="native" />
      </id>
      <property name="latitude" type="double"/>
      <property name="longitude" type="double"/>
      <property name="height" type="double"/>
   </class>
</hibernate-mapping>


There are several classes that SHOULD contain a reference to their own Geodetic object. I started small by putting the following in one of those classes mapping files:

Code:
<many-to-one name="location" class="dao.coordinate.Geodetic" cascade="all" lazy="false"/>


All was well at that point and the code ran fine. However, as soon as I inserted the previous code into another classes mapping file things went wrong. When I tried to save that object to the database I get the following exception:

Code:
processRequests   got exception while processing   [org.hibernate.HibernateException: identifier of an instance of dao.coordinate.Geodetic was altered from 38 to 37


Any idea why it works when the Geodetic class is only saved as a reference in one class but the moment two classes try to save references to it there is trouble?[/quote]


Top
 Profile  
 
 Post subject: Anybody have any ideas?
PostPosted: Thu Jan 31, 2008 11:54 am 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
I'm still struggling with this problem, does anybody have a suggestion?


Top
 Profile  
 
 Post subject: Re: Anybody have any ideas?
PostPosted: Thu Jan 31, 2008 11:58 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
EdLaFave wrote:
I'm still struggling with this problem, does anybody have a suggestion?


What is the id property in the class? and also show me the whole exception stack trace.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 11:54 am 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
Here are the basics of each class:

Geodetic:

Code:
public class Geodetic {
   private Long id = null;
   private double longitude = 0;
   private double latitude = 0;
   private double height = 0;
}


Code:
<hibernate-mapping package="dao.coordinate">
   <class name="Geodetic" table="CRD_Geodetic">
      <id name="id" column="id">
         <generator class="native" />
      </id>
      <property name="latitude" type="double"/>
      <property name="longitude" type="double"/>
      <property name="height" type="double"/>
   </class>
</hibernate-mapping>


ClassA:
Code:
public class ClassA{
   private Long id = null;
   private Geodetic location = new Geodetic();
}


Code:
<hibernate-mapping package="dao.package1">
   <class name="ClassA" table="CRD_ClassA">
      <id name="id" column="id">
         <generator class="native" />
      </id>
      <many-to-one name="location" class="dao.coordinate.Geodetic" cascade="all" lazy="false"/>
   </class>
</hibernate-mapping>


ClassB:
Code:
public class ClassB{
   private Long id = null;
   private Geodetic location = new Geodetic();
}


Code:
<hibernate-mapping package="dao.package1">
   <class name="ClassB" table="CRD_ClassB">
      <id name="id" column="id">
         <generator class="native" />
      </id>
      <many-to-one name="location" class="dao.coordinate.Geodetic" cascade="all" lazy="false"/>
   </class>
</hibernate-mapping>


A stack trace of the error with this configuration is:

Code:
1    13.02.2008 10:40:51.738   1,000   SEVERE   Thread[ULC Communication Controller Thread,6,main]   com.ulcjava.base.server.ULCSession   processRequests   got exception while processing   [org.hibernate.HibernateException: identifier of an instance of dao.coordinate.Geodetic was altered from 57 to 33
   at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:58)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at emst.dao.player.PlayerManager.getSimulatedPlayers(PlayerManager.java:146)
   at emst.sim.SimulationManager.generateSimulatedPlayer(SimulationManager.java:489)
   at emst.dao.package1.ClassA.initialize(ClassA.java:207)
   at emst.dao.package1.ClassAFactory.buildFromXML(ClassAFactory.java:84)
   at emst.dao.xmlconversion.ClassAConverter.startElement(ClassAConverter.java:144)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
   at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
   at javax.xml.parsers.SAXParser.parse(Unknown Source)
   at javax.xml.parsers.SAXParser.parse(Unknown Source)
   at emst.dao.xmlconversion.ClassAConverter.parseEntitiesFromXMLFile(ClassAConverter.java:123)
   at emst.dao.xmlconversion.ClassAConverter.convertEntitiesFromXMLFile(ClassAConverter.java:85)
   at emst.sim.SimulationManager.addExerciseModule(SimulationManager.java:413)
   at emst.sim.SimulationManagerFactory.createManager(SimulationManagerFactory.java:63)
   at emst.sim.JointExercise.<init>(JointExercise.java:63)
   at emst.sim.JointExerciseFactory.createJointExercise(JointExerciseFactory.java:132)
   at emst.sim.JointExerciseFactory.createJointExercise(JointExerciseFactory.java:85)
   at emst.sim.JointExerciseFactory.createJointExercise(JointExerciseFactory.java:171)
   at emst.portal.scheduler.individual.IndividualExerciseScheduler.join(IndividualExerciseScheduler.java:279)
   at emst.portal.scheduler.individual.IndividualExerciseScheduler.nextFrame(IndividualExerciseScheduler.java:196)
   at emst.portal.scheduler.individual.IndividualSchedulerGeneralInfoView$5.actionPerformed(IndividualSchedulerGeneralInfoView.java:410)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.ulcjava.base.shared.internal.ReflectionUtilities.invokeMethod(ReflectionUtilities.java:29)
   at com.ulcjava.base.application.ULCProxy.dispatchEvent(ULCProxy.java:128)
   at com.ulcjava.base.application.ULCProxy.processActionEvent(ULCProxy.java:363)
   at com.ulcjava.base.application.ULCProxy$ULCProxyDispatcher.processActionEvent(ULCProxy.java:19)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.ulcjava.base.shared.internal.ReflectionUtilities.invokeMethod(ReflectionUtilities.java:29)
   at com.ulcjava.base.application.ULCProxy.a(ULCProxy.java:339)
   at com.ulcjava.base.application.ULCProxy.handleEvent(ULCProxy.java:146)
   at com.ulcjava.base.application.ULCProxy$ULCProxyDispatcher.handleEvent(ULCProxy.java:30)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.ulcjava.base.shared.internal.ReflectionUtilities.invokeMethod(ReflectionUtilities.java:29)
   at com.ulcjava.base.application.ULCProxy.d(ULCProxy.java:172)
   at com.ulcjava.base.application.ULCProxy.handleRequest(ULCProxy.java:185)
   at com.ulcjava.base.server.ULCSession.a(ULCSession.java:230)
   at com.ulcjava.base.server.ULCSession.processRequests(ULCSession.java:212)
   at com.ulcjava.base.development.DevelopmentContainerAdapter.processRequests(DevelopmentContainerAdapter.java:0)
   at com.ulcjava.base.development.DevelopmentConnector.sendRequests(DevelopmentConnector.java:12)
   at com.ulcjava.base.client.UISession$k_.run(UISession$k_.java:71)
   at java.lang.Thread.run(Unknown Source)
]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 12:52 pm 
Newbie

Joined: Mon Jan 28, 2008 1:55 pm
Posts: 19
If this is helpful I have boiled the code down to the most simple test case. If I perform the following actions in order then everything is okay:

1.) Create and save an object of ClassA to the database.
2.) Create and save an object of ClassB to the database.

However, if I execute those in the reverse error I get the identifier altered error:

1.) Create and save an object of ClassB to the database.
2.) Create and save an object of ClassA to the database.

This led me to try the following order and the same error was generated:

1.) Create and save an object of ClassA to the database.
2.) Create and save an object of ClassB to the database.
3.) Create and save an object of ClassA to the database.

So it seems as though saving instances of ClassA after an instance of ClassB has been saved causes the error. Any idea why? ClassA and ClassB both contain a Geodetic object and use the exact same XML to map to it. Any help would be very much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 8:47 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I am not so sure if this is related to the problem but put a column name for the many-to-one mappings. I don't know what the default behaviour is. Also, please give me the java code for the tests. That will help me to do a test on my side.



Farzad-


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