Issue Details (XML | Word | Printable)

Key: HHH-779
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Alessandro Rizzi
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

Assertion failure occured with Hibernate 3 saving objects

Created: 22/Jul/05 09:56 AM   Updated: 24/Sep/05 06:50 PM
Component/s: core
Affects Version/s: 3.0.5
Fix Version/s: 3.1 beta 2

Time Tracking:
Not Specified

Environment: Hibernate 3.0.5, SQL Server 2000 SP2


 Description  « Hide
I have this exception:

SEVERE: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)

org.hibernate.AssertionFailure: null identifier
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:33)
at org.hibernate.event.def.DefaultEvictEventListener.onEvict(DefaultEvictEventListener.java:51)
at org.hibernate.impl.SessionImpl.evict(SessionImpl.java:702)
at testHib3.starter.go(starter.java:69)
at testHib3.starter.main(starter.java:22)
org.hibernate.AssertionFailure: null identifier
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:33)
at org.hibernate.event.def.DefaultEvictEventListener.onEvict(DefaultEvictEventListener.java:51)
at org.hibernate.impl.SessionImpl.evict(SessionImpl.java:702)
at testHib3.starter.go(starter.java:69)
at testHib3.starter.main(starter.java:22)

with this code:

Session hibSession = sf.openSession();
tstDACmain m = (tstDACmain)hibSession.load( tstDACmain.class, new Long(1) );
m.setId( null );
hibSession.evict( m);
hibSession.saveOrUpdate( m );
hibSession.flush();

and this mapping document:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 1.1//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="testHib3.tstDACmain" table="tst_main">
<id column="id" name="id" type="long">
<generator class="native"></generator>
</id>
<property column="des" length="50" name="des" not-null="false" type="string"/>
</class>
</hibernate-mapping>


Notice that if you change the code like this:

From:
tstDACmain m = (tstDACmain)hibSession.load( tstDACmain.class, new Long(1) );

To:
tstDACmain m = new tstDACmain();
hibSession.load( m, new Long(1) );

then it works perfectly. No error occurs, and the object is saved in the database.

I did not have this error on Hibernate 2.1.8.

Regards
Alessandro Rizzi


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Alessandro Rizzi added a comment - 22/Jul/05 09:59 AM
I forgot to say that I have the same exception in a similar situation, and I'd like not to look for another workaround, like in the example above, also because I do not know how many similar situations I will find in the future.
Alessandro

Gavin King added a comment - 24/Jul/05 11:53 PM
Now throws IllegalArgumentException

Alessandro Rizzi added a comment - 26/Jul/05 12:14 PM
Sorry but I do not understand. Do you mean that now I will always have the IllegalArgumentException?
Or only in the case reported above?
In both cases, why?
Why it works right in Hibernate 2.1.8, and throws the exception now?
And, most important: why 1 overload of session.load() works and the other one cause an exception? (While in 2.1.8 both works right).
Is there any mistake in my code?

Reagards
Alessandro Rizzi

Andrew Fung added a comment - 24/Sep/05 06:50 PM
I had a similar problem with the use of Session.evict() and subsequently trying to reassociate within the same session (i.e. before Session.close) using Session.save() (or update).

For the most part, it seemed to resolve if I called Session.flush() after the Session.evict(). I still had problems trying to use the evicted instance to Session.load() an object for deletion though.

I ended up tossing the whole idea out and going with the optimistic concurrency collision detection that Hibernate supports (i.e. versions/timestamps).