-->
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.  [ 4 posts ] 
Author Message
 Post subject: AutoFlush and Interceptors
PostPosted: Wed Feb 09, 2005 5:20 pm 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
I am finding the onFlushDirty() method on my Interceptor is being repeatedly invoked when I would expect it to only be invoked once.

Here is the scenario:

I have a dirty entity. In the same session I have several calls to session.getNamedQuery().list(). Each of these calls triggers my Interceptor.

Here is what I see is happening:

Each call to session.getNamedQuery().list() makes a call to session.autoFlushIfRequired(), which ultimately calls session.flushEntity() for each entity in the session. For a dirty entity, this invokes my Interceptor. So far so good.

But the trouble is, since session.execute() is never called until I finally commit the transaction, the loadedState of the dirty entity never gets updated. Therefore each call to session.getNamedQuery().list() is triggering the interceptor. This does not seem correct behaviour to me.

I was wondering about setting the AutoFlush mode to Commit, but because I'm using spring's HibernateTransactionManager I'd rather not.

I'm using 2.1.7

Any ideas?


Top
 Profile  
 
 Post subject: Is this a bug?
PostPosted: Thu Feb 10, 2005 7:41 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
Perhaps I'm doing something wrong, but this seems like a bug to me.

I have an intereceptor set up, and in the code below each call to session.getNamedQuery() is triggering the interceptor. The only way round appears to be to set the flushMode to commit.

Code:
    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();
    //session.setFlushMode(FlushMode.COMMIT);
   
    MyEntityPK pk = new MyEntityPK ();
    pk.setID(new Integer(1));
   
//Get Entity
    MyEntity entity = (MyEntity ) session.load(MyEntity .class, pk);

//Make entity dirty
    entity.setSomeProperty(new Integer(99));

//Exeute some named queries - each one triggers the interceptor!!??
    List results = session.getNamedQuery("someQuery").list();
    results = session.getNamedQuery("someOtherQuery").list();

//finish off..
    tx.commit();
    session.close();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 1:22 pm 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
Sorry..........after several hours more debugging I've finally nailed this one down to a flawed hashCode(). My fault. I knew it would be.
Hibernate is God again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 4:48 am 
Newbie

Joined: Fri Mar 14, 2008 4:20 am
Posts: 17
What exactly was the problem with your haseCode()-method?


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