-->
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.  [ 1 post ] 
Author Message
 Post subject: interceptor/ transactions (hib3)
PostPosted: Thu Apr 06, 2006 6:30 pm 
Newbie

Joined: Wed Mar 22, 2006 6:30 am
Posts: 9
hi,

plain vanilla session-factory-scoped interceptor: is there anyway to participate in the transaction of the caller?

e.g. a Report object is being saved. in the onSave method body i would like to insert a record into a dependant ReportInfo table.

because of the FK constraint in the dependant ReportInfo table, i can not insert the dependent record unitil the parent record has commited. the following code snippet will cause the FK contraint violation:

public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {

if(entity instanceof Report == true){
log.info("onSave(): " + entity.getClass());
Report r = (Report)entity;
ReportInfo i = synchIntComp(r);

Session newSession =
HibernateUtil.sessionFactory.openSession(
HibernateUtil.currentSession().connection());

Transaction tx = newSession.beginTransaction();
newSession.save(i);
tx.commit();
newSession.flush();
newSession.close();
}
return false;
}


thanks!

tom


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.