-->
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.  [ 11 posts ] 
Author Message
 Post subject: is pojo dirty
PostPosted: Mon Sep 26, 2005 10:41 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Is it possible to determine if a certain pojo is dirty ?
I know there's the session.isDirty method, but I'd like to know if there is a similar way to determine if a single pojo is dirty.
Thanks.

Simone


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 11:08 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
Well, a really pathetic way would be to create a new session, associate the pojo of interest and then check the isDirty method you referred to.

I'm not aware of a way to check against an individual pojo. What is the usage scenario you're shooting for. The event listeners could be helpful depending on what you're looking for.


JOe

_________________
Joe W


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 4:22 am 
Newbie

Joined: Thu Dec 16, 2004 12:56 pm
Posts: 9
I have the same problem ! Knowing the state of a single pojo in a session is a typical requirement for most type of GUIs.
This can be a very good anhancement request for the next release of Hibernate: getSession.isDirty(pojo)
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 10:21 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
I don't like to open a new Session only for knowing if the pojo is dirty: this information should be already available to Hibernate.
I took a look at the Event Listener, but those events are to be fired too late.
Any other suggestion, please ?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 12:25 pm 
Newbie

Joined: Thu Jul 28, 2005 12:24 pm
Posts: 7
mrossix wrote:
This can be a very good anhancement request for the next release of Hibernate: getSession.isDirty(pojo)
Marco


I totally agree with you Marco.
In some situations i absolutely need to know the state of a pojo (specially working with long user transactions) and i'm surprising there is not a session method to retrieve this kind of information.
Reading Hibernate in Action i've found (page 118 at the begin) :

Quote:
We call this Automatic dirty checking [...]this state isn't visible to the application. We call this feature transparent transaction-level-write-behind [...]hides this detail from the application.


So i guess we cant have these informations "by design".
I hope this will change in the future, honestly i don't see any drawback to have access to state information.


s7


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 8:54 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Does anyone have other suggestions ?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 09, 2005 1:20 pm 
Newbie

Joined: Sat Aug 20, 2005 5:14 am
Posts: 9
Hi, did you guys get your answer??

I am looking for EXACTLY the same answer as well... Pls kindly let me know if you have a better solution...


Here is my urgly way to find ALL modified object in a session...

Code:

         SessionImpl sessImpl = (SessionImpl) DAOUtil.getSession();
         PersistenceContext pc = sessImpl.getPersistenceContext();
         Map map_ = pc.getEntityEntries();

         for (Iterator it = map_.entrySet().iterator(); it.hasNext();)
         {
            Map.Entry en = (Map.Entry) it.next();

            Object obj = en.getKey();
            EntityEntry ee = (EntityEntry) en.getValue();
            SingleTableEntityPersister step = (SingleTableEntityPersister) ee.getPersister();

            Object oldVals[] = ee.getLoadedState();
            Object newVals[] = step.getPropertyValues(obj, sessImpl.getEntityMode());
            
            // this array contains all modified column idx
            int[] mods = step.findModified(newVals, oldVals, obj, sessImpl);

            // use getPropertyColumnNames to get the modified column name
            // modified column names


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 9:37 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
We talked to Christian Baurer in Barcelona about this problem, and he agreed with us that such an API (session.isDirty(pojo)) is useful.
He will evaluate (with the rest of the Hibernate group) adding it in the next versions.
But your method of retrieving the dirty pojos is not so bad.
Simone


Top
 Profile  
 
 Post subject: is pojo dirty
PostPosted: Mon Dec 18, 2006 9:30 am 
Newbie

Joined: Mon Dec 18, 2006 8:32 am
Posts: 1
pb16385 wrote:
We talked to Christian Baurer in Barcelona about this problem, and he agreed with us that such an API (session.isDirty(pojo)) is useful.


Other potential Session methods closely related to the suggested isDirty(pojo) that could be really useful for an application would be:
* Is a specified attribute dirty:
Code:
isDirty(Object pojo, String attributeName): boolean

* What is the old (loaded) value of an attribute:
Code:
getLoadedValue(Object pojo, String attributeName) : Object

* possibly also; What is the old (loaded) state of an object:
Code:
getLoadedValue(Object pojo): Object


Since this information is available to Hibernate, it seems unnecessary to have to keep track of this information separately.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 10:06 pm 
Newbie

Joined: Tue Jun 20, 2006 11:51 am
Posts: 14
Does anyone know whether there's been any progress or decisions regarding the session.isDirty(pojo) feature request?

Thanks,
Gary


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 03, 2007 3:27 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
The strategy I use is that I wrap all my hibernate transactions inside a command so I can catch the exception in 1 place. If an exception is thrown, I mark the POJO dirty. It is not marked clean until a successful transaction. Actually I suppose I can mark it dirty at the beginning of the XA and mark it clean when the XA is done.

These objects I never modify outside of a transaction. They only end up "dirty" when a XA fails.

Anyway, perhaps if you can get at the proxy you can tell?


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