I have a simple class, lets say MyClass, with a reference inside to another MyClass instance called "parent".
When I try to query for all MyClass instances with a null parent, I get this exception: HibernateSystemException: identifier of an instance of MyClass altered from 100 to 100.
My query looks like: "from MyClass mc where mc.parent is null"
My hibernate version is Hibernate 2.1.3.
In my test, I have two instances of MyClass in the database, with ids of 100 and 101, and parent values of null. Nothing else is going on in the database.
I don't quite understand this exception. I tried searching the forum for similar exceptions, but I couldn't find anything. If anyone could shed any light on this, I would appreciate it. Thanks :)
my mapping
Code:
<class name="MyClass" table="my_class">
<id name="id" column="id" type="int" unsaved-value="-1">
<generator class="assigned"/>
</id>
<property name="name" column="name" not-null="true"/>
<many-to-one
name="parent"
class="MyClass"
column="parent_id"
/>
</class>
the exception
Code:
org.springframework.orm.hibernate.HibernateSystemException: identifier of an instance of MyClass altered from 100 to 100; nested exception is net.sf.hibernate.HibernateException: identifier of an instance of MyClass altered from 100 to 100 net.sf.hibernate.HibernateException: identifier of an instance of MyClass altered from 100 to 100 at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2631) at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2454) at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2447) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2249) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228) at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:202) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:151) at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170) at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:328) at