-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to get the state of persistent entities ?
PostPosted: Wed Apr 28, 2004 5:40 am 
Newbie

Joined: Wed Apr 28, 2004 5:32 am
Posts: 12
hi,

how can i get the state of a persistent entity ?
The class EntityEntry seems to hold the state i'm looking for but i can't figure out how to get it. (I don't want to use Interceptor).

Thanks.

Hibernate 2.1.2, Sybase ASA 6, ASE 12.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 11:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What do you mean by the state of a persistent entity ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 4:38 am 
Newbie

Joined: Wed Apr 28, 2004 5:32 am
Posts: 12
we use DAO pattern to hide persistence service (Hibernate API) calls.
In our standard BusinessDAODefaultImpl we have two methods :

- delete(Business)
- synchronize(Business) (which means save or update)

We have one DAO class for one Business class.

A PersistenceService interface is used to hide Hibernate.

Excerpt of synchronize method :

Transaction transaction = null;

/* Interception */
prepareSynchronization(business);
try {
transaction = getPersistenceService().getTransaction();

/* Interception */
beforeSynchronization(business);

persistenceService.delete(business);
persistenceService.flush();

/* Interception */
afterSynchronization(business);

transaction.commit();

/* Interception */
terminateSynchronization(business);

} catch(Exception e) {
Logs.logError(getClass(),e.toString());
}


As you can see some interception methods are called :

- before transaction is opened and after transaction is committed
- before delete and after flush

This special use of Hibernate is required because we have to rebuild in Java some old applications that used to do weird things (power builder apps) :

- in afterSynchronization : maybe you must reload your business from database because there is a trigger which has updated a row
- in beforeSynchronization : maybe you want to call a stored proc to get a primary key (same transaction needed )
- ....

This kind of things should be rare in our new Java applications (i hope so) but we have to permit this.
I've seen two ways in Hibernate to implement this :

- use Lifecycle interface
- use Interceptor

It appears to me that it does not fit our needs. (i'm not sure)

Anyway such weird things are tied to Business class. If we use ten Business classes maybe one needs it. The DAO way seems to be
the best compromise.

So in my callbacks before, after etc .. I would like to know what is the state of Business according to the persistence service.

In our case the default persistence service is Hibernate. I would like to ask the Hibernate Session what is the state of a persistent Business it holds.

int state = persistenceService.getState(Business);
if(state == UPDATED)
....do my dirty things

Is it possible to get such information with Hibernate session?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 6:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No. There is only the onFlushDirty method of interception

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 10:15 am 
Newbie

Joined: Wed Apr 28, 2004 5:32 am
Posts: 12
I've have seen this announcement in Roadmap :

"
Hibernate 2.2

* refactor Hibernate to allow many more extension points, including addition of a full event API

"


Can these new features help us ?

Do you have any idea to solve our problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 10:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The new event API will help with parts of this. The parts lacking would be your methods relating to transaction lifecycle. But there is currently no set date for any type of release of features currently on the v22branch. So your options there would be to either wait for the release or get the source from cvs and build it yourself.

This would be a (highly unsupported) hack, but SessionImpl has methods to obtain the information you are looking for in your initial post. You could simply cast your Session reference to SessionImpl and make the appropriate calls.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 3:11 am 
Newbie

Joined: Wed Apr 28, 2004 5:32 am
Posts: 12
"This would be a (highly unsupported) hack, but SessionImpl has methods to obtain the information you are looking for in your initial post. You could simply cast your Session reference to SessionImpl and make the appropriate calls."

We have planned to do this hack if no clean solution is available.
We are currently building our framework, we'll start to built real applications at the end of year.
I hope we can wait for Hibernate 2.2.

Thanks to Hibernate team for your support.


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