-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question about Hibernate behavior; maybe WAD but seems odd
PostPosted: Mon Aug 29, 2005 10:47 pm 
Newbie

Joined: Thu Jan 27, 2005 12:26 pm
Posts: 5
Is the following normal behavior for Hibernate?

Context: I have a UI that uses long-running hibernate sessions to manipulate Java objects, then saves them back to the database in one transaction when I am done.

[list=]
I open a hibernate session.
I load an entity A from the database into memory.
I create an empty element B under A, which goes into a many-to-one list under A. Important: B has certain fields with not-null="true".
Before filling in all the not-null B fields, I perform another operation which causes a query to be executed.
The execution of the query causes a flush to occur, which throws an exception "PropertyValueException: not-null property references a null or transient value", because I had not yet filled in all of the not-null fields in B
[/list]

I saw the FlushMode.COMMIT option, but I also read in Gavin's book that it is not recommended to change this setting.

Is my only option to create B as a standalone entity, and fully validate it before attaching it to A? That is going to be very awkward, because this UI is supposed to let the users play around with the data, adding and removing and changing perhaps many things before committing.

I guess another option would be to forego the not-null constraint, but that would be a shame not to let the database help me enforce data integrity rules.

I feel I must be missing something. Any insight is much appreciated.[/list]


Top
 Profile  
 
 Post subject: Think I found the answer
PostPosted: Tue Aug 30, 2005 12:46 am 
Newbie

Joined: Thu Jan 27, 2005 12:26 pm
Posts: 5
I was wondering what evict() was for! It seems that it's a good idea to evict the entity from the session while it is being edited, then call saveOrUpdate() on it when the user is done.

I have done this and it seems to be working so far.

Is this the standard practice? Any gotchas with this approach?


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