-->
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: PreCommit listener
PostPosted: Thu Jan 03, 2008 8:41 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
I wish to put a persistence flag in my JPA entities to indicate the JPA entity is persistent.
This flag will begin at false to indicate the entity is not persistent. If the application persists and commits this entity it should go to true to indicate entity is persistent.

I need a hook to set this flag to true.

I can't use @PrePersist because this gets invoked at the persist method invocation. The problem here is commit() may never get called.

I can't use @PostPersist because this happens after the entity gets inserted in the database which means the wrong value for the flag will get inserted in the database.

any ideas?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 10:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I am not quite sure what you try to achieve with this flag, maybe you could explain your use case in more detail.

Would it not be enough to just check the hibernate id of the instance to determine whether the object was persisted? If the id is null you have a new un-persisted object, if the value is set you know that you got the object from the db.


Top
 Profile  
 
 Post subject: Re: PreCommit listener
PostPosted: Fri Jan 04, 2008 1:33 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
breako wrote:
Hi,
I wish to put a persistence flag in my JPA entities to indicate the JPA entity is persistent.
This flag will begin at false to indicate the entity is not persistent. If the application persists and commits this entity it should go to true to indicate entity is persistent.

I need a hook to set this flag to true.

I can't use @PrePersist because this gets invoked at the persist method invocation. The problem here is commit() may never get called.

I can't use @PostPersist because this happens after the entity gets inserted in the database which means the wrong value for the flag will get inserted in the database.

any ideas?

Thanks

Hi,
I solved this by using postPersist() event and not making the variable persistable.
This is this just a utiility API in our current architecture, we are migrating to JPA hibernate.
Rgds


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.