-->
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.  [ 2 posts ] 
Author Message
 Post subject: Writing into DB with Interceptor
PostPosted: Sat Feb 28, 2004 3:52 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
Hi,

I'm trying to intercept the changes to the database with Interceptor and write some data about these changes into the DB.

The problem is that when I try to update the ObjectA into the DB the interceptor intercept the request and insert some data into the DB, but when this information is written the interceptor is called again for the ObjectA, and the program goes into a loop...

I guess this happens because the ObjectA is flushed again, and the interceptor is called everytime something uses the DB.

Is that correct?
What should I do?

Thanks.

Some code of mine:

public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types )
{
try
{
RegistroHistorico regHist = this.carregaRegistroHistorico(
entity, LogHistoricoInterceptor.OPERACAO_UPDATE);

fac.writeLogAtualizacao(regHist);
}catch(Exception err)
{
err.printStackTrace();
}

return false;
}


public boolean onSave(
Object entity,
Serializable id,
Object[] state,
String[] propertyNames,
Type[] types )
{
try
{
if (! (entity instanceof RegistroHistorico))
{
RegistroHistorico regHist = this.carregaRegistroHistorico(entity, LogHistoricoInterceptor.OPERACAO_INSERT);

fac.writeLogAtualizacao(regHist);
}
}catch(Exception err)
{
err.printStackTrace();
}

return false;
}

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 7:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are not allowed to invoke the session from an Interceptor callback! This is described in the JavaDoc. Instead, you could use a different session, on the same connection.


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