-->
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: previousState Null during Complex Validations
PostPosted: Sat Jan 31, 2004 12:50 am 
Beginner
Beginner

Joined: Fri Jan 02, 2004 3:27 am
Posts: 23
Location: Hong Kong
I have implemeneted the Complex Validations using Interceptor pattern
Yet, I got the problem is the during the callback onFlushDirty, the field previousState is NULL. Which result the DeltaSet cannot calcaulate correctly.

I am using Session Bean to do the update
Code:
// Remote Method
public void updateUom(Uom uom) throws HibernateException, NamingException {
  Session sess = HibernateSessionFactoryUtil.openSession();
  sess.update(uom);
  sess.flush();
  sess.close();
}

The problem is caused by incoming parameter uom is serialized before. ( queried by another EJB remote method ). That mean the uom is come from another hibernate session and that session is closed.

The problem can be simply repeated by
Code:
Session sess = sessions.openSession(new ValidationInterceptor());
Criteria crit = sess.createCriteria(Uom.class);
List r = crit.list();
sess.close(); // close previous session
      
Session sess2 = sessions.openSession(new ValidationInterceptor());
Uom o = (Uom) r.get(0);
o.setUomDesc("NEWVALUE");
sess2.update(o);
sess2.flush(); // previousState is NULL during callback onFlushDiery

The problem may be solved by using sess.replicate method instead of sess.update. But replicate will update all the object graph instead according to cascade setting which I want.

Does anyone have a better solution on it ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 2:23 am 
Beginner
Beginner

Joined: Fri Jan 02, 2004 3:27 am
Posts: 23
Location: Hong Kong
Anyone have idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 2:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
of course, hibenate does not know the current db state in the case of update()!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 8:41 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
hiebrnate has a strange behaviour in cascade collections saving new entities.

situation: entity E has a cascade=all collection of F's.

after loading E, adding a new F into it's collection and updating E, hibernate calls onFlushDirty on the freshly created F instance, and later on calls an onSave, too.

in the onFlushDirty call the previous state is null. i've not seen it documented, and it's not intuitive either. (at least for me)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Why exactly is it not intuitive that an insert would not have previous state?

And if you say "because its already been saved", please stop and go read the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 05, 2004 8:26 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
steve wrote:
Why exactly is it not intuitive that an insert would not have previous state?


i meant it's not intuitive that hibernate calls onFlushDirty on an entity that is currently being inserted. then what is onSave for?

what is intuitive for me is one callback method for update situations and another one for save situations. now we have one for save and one for save/update.

and still it would be ok, if it were documented in that way. but:

"Called when an object is detected to be dirty, during a flush."

this implies for me that the object is already known to hibernate, so onFlushDirty is only called for update()'s. again, it could be only my bugous thinking...

but if you accept a subjective opinion, i have a feeling that the wording of the documentation is written in the context of the hibernate implementation, not in the context of generic o/r mapping. which implies some knowledge about the hibernate code, without which many things are not clear or behave unexpected.

again it's just an opinion.

steve wrote:
And if you say "because its already been saved", please stop and go read the documentation.


i've met this attitude so many times in this project... you don't give a thing on user feedback. which is probably reasonable guessing the noise made by newbies, but still it shouldn't be the way...

the less you listen to the annoyance of users, the more noise will be generated when unexpected behaviour is seen.

don't misunderstand me, still a huge thanks for hibernate!!! i really appreciate the free work you do on this project!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 9:33 am 
Newbie

Joined: Fri Oct 29, 2004 9:00 am
Posts: 1
i think i have found a bug in ValidationInterceptor. CollectionPropertyDelta.anyChangeDetected is implemented like this:
Code:
public boolean anyChangeDetected()
    {
        return (!getAdditions().isEmpty() && !getRemovals().isEmpty());
    }

it should be
Code:
return (!getAdditions().isEmpty() || !getRemovals().isEmpty());


should not it?

i tried to post a comment on the wikipage, but i did not manage...


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.