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 ... nhancementAny feedback is welcome
S.