-->
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: em.persist and not fully initialized entity
PostPosted: Fri Nov 04, 2011 6:57 am 
Newbie

Joined: Wed Apr 23, 2008 11:11 pm
Posts: 19
Hi,

I am using Hibernate 3.6.5

I would like to be able to mark an entity as being managed in the course of a transaction at any time and regardless of the state of the entity.

My problem is that em.persist(x) could not be called if x has non null fields which are not set (yet)

Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: FooEntity.businessId


I am trying to move a legacy system to hibernate and this legacy system has the notion of long unit of work (in short, what the extended mode for the entity manager does). In this system I mark an object "to be persisted" with that unit of work and when I commit, an actual transaction is created and everything is flushed to the database. So it's fine to first mark the object as managed and then set fields, including mandatory ones. I can't get that working with Hibernate.

Is there an internal method I could use that basically states that the object is managed and an ID is assigned to it? Right now I am calling the ID generator myself and I call persist in the commit but that seems quite fragile to me.

This patch seems like it would solve my problem: https://github.com/sfraser/Hibernate-Co ... nhancement

Any feedback is welcome

S.


Top
 Profile  
 
 Post subject: Re: em.persist and not fully initialized entity
PostPosted: Mon Nov 21, 2011 6:58 am 
Newbie

Joined: Wed Apr 23, 2008 11:11 pm
Posts: 19
Anyone?


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.