-->
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.  [ 4 posts ] 
Author Message
 Post subject: NullPointerException - there is no snapshot of a collection
PostPosted: Fri Aug 27, 2004 4:17 am 
Newbie

Joined: Thu Sep 11, 2003 1:50 am
Posts: 6
The variable sn is null, there is no snapshot of the set. sn.size() causes the NPE

Hibernate version:

2.1

Mapping documents:

<set name="logs" lazy="true" inverse="false" cascade="none" sort="natural">
<key column="subject"/>
<composite-element class="org.concern.controller.Log">
<property name="activity"
type="java.lang.String"
update="true"
insert="true"
column="activity"
length="64"/>

<property name="success"
type="boolean"
update="true"
insert="true"
column="success"/>

<property name="message"
type="java.lang.String"
update="true"
insert="true"
column="message"
length="512"/>

<property name="details"
type="java.lang.String"
update="true"
insert="true"
column="details"
length="512"/>

<property name="timestamp"
type="java.sql.Timestamp"
update="true"
insert="true"
column="timestamp"/>
</composite-element>
</set>

Code between sessionFactory.openSession() and session.close():

sessions.getSession().lock(subject, LockMode.UPGRADE);
subject.setDestroyed(true);
Log log = new Log("", "DESTROYED");
log.setSuccess(true);
if (subject.getLogs() == null)
subject.setLogs(new TreeSet());
subject.getLogs().add(log);

Full stack trace of any exception that occurs:

java.lang.NullPointerException
at net.sf.hibernate.collection.Set.equalsSnapshot(Set.java:54)
at net.sf.hibernate.impl.SessionImpl$CollectionEntry.isDirty(SessionImpl.java:328)
at net.sf.hibernate.impl.SessionImpl$CollectionEntry.preFlush(SessionImpl.java:336)
at net.sf.hibernate.impl.SessionImpl.preFlushCollections(SessionImpl.java:2738)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2201)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2186)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
[...]

Debug level Hibernate log excerpt:

Hibernate: select subject0_.id as x0_0_ from Subject subject0_ where (subject0_.userValue=? )
Hibernate: select subject0_.id as id0_, subject0_.userValue as userValue0_, subject0_.locked as locked0_, subject0_.destroyed as destroyed0_ from Subject subject0_ where subject0_.id=?
Hibernate: select id from Subject where id =? for update
Hibernate: select timers0_.timeout as timeout__, timers0_.subject as subject__ from timers timers0_ where timers0_.subject=?
Hibernate: select logs0_.activity as activity__, logs0_.success as success__, logs0_.message as message__, logs0_.details as details__, logs0_.timestamp as timestamp__, logs0_.subject as subject__ from logs logs0_ where logs0_.subject=?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I guess you have changed the object since you detached it, and changed the collection reference. This is not allowed if you are going to use lock().

I will try and track down the cause and make Hibernate throw a more helpful exception. NPEs are always bad.

It would help me a lot if you could submit a very simple test case to JIRA. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:29 am 
Newbie

Joined: Thu Sep 11, 2003 1:50 am
Posts: 6
gavin wrote:
I guess you have changed the object since you detached it, and changed the collection reference. This is not allowed if you are going to use lock().


No. I was even more stupid:

The Log class had bad equals and hashCode methods, that presumably threw NPEs. I changed them and now it's working. Probably those NPEs in equals or hashCode prevented hibernate from making the snapshot.

It would have helped a lot, if hibernate wouldn't swalllow those exceptions.

gavin wrote:
I will try and track down the cause and make Hibernate throw a more helpful exception. NPEs are always bad.

It would help me a lot if you could submit a very simple test case to JIRA. Thanks.


Do you still need a test case?

Thanks a lot,

Holger


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate doesn't swallow any exceptions, so its kinda confusing...


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