-->
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.  [ 3 posts ] 
Author Message
 Post subject: Creation of PersistentSet
PostPosted: Fri Sep 16, 2005 4:22 am 
Newbie

Joined: Fri May 27, 2005 6:16 am
Posts: 14
Hi,

I am using hibernate3 to manage my relational persistence, and it is working great. I have one problem however:

I create a parent object. When I restart my application its child sets are created lazily without a problem. When, in the same session, I try to add a newly created child to it, I get a NullPointerException. It seems that the PersistentSet to hold the child references are only created when restarting the application. Is there a way to tell hibernate to create the sets right after creating the parent Object? In the database the child is linked to the arent, it is only in the hibernate that there is a problem. Even refreshing the parent does not help.

A working workaround is to create a Query "from Parent where Id = :newid". and put that in the session cache.

Any solutions on that one?

Regards,
Leen Toelen


Top
 Profile  
 
 Post subject: Following the posting guidlines might lead to better help...
PostPosted: Fri Sep 16, 2005 8:39 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Can you please post the exception and possibly an isolated example?

I'd guess that your object doesn't create a set implementation when it needs to. But... I can't tell because you didn't post an example. :)

Also: Session.load() or Session.get() should be used instead of "from Parent where Id = :newid" if Id is the key. Since you didn't post mappings, I can't tell. :)

Anyway, if you really want a solution you need to describe the problem more fully, thanks!


Top
 Profile  
 
 Post subject: Fixed
PostPosted: Fri Sep 16, 2005 8:45 am 
Newbie

Joined: Fri May 27, 2005 6:16 am
Posts: 14
Hi,

I solved the problem by doing

session.refresh(parent);
parent.getChildren.add(child);

This always creates the children PersistentSet, even if parent has only been just created.

Best regards,

Leen Toelen
http://www.peakadilly.com


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