-->
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: Is it possible to get the instance of an Interceptor? v 2.1
PostPosted: Mon Oct 03, 2005 9:24 am 
Newbie

Joined: Mon Oct 03, 2005 8:37 am
Posts: 6
Location: Charlotte, NC
Hibernate version: 2.1.6

Name and version of the database you are using: Oracle 9i


Hi folks,
I've resently started using the "long sessions" pattern (Hibernate in Action - page 326) in my servlets. I'm using the HibernateUtil class and have implemented the servlet filter as described. All is well! However, I have a slight issue.
I use an Interceptor to create history for object changes (a story in itself). This Interceptor has to know about the "owner" of the changes (person making the the changes to the object). Previously I was using detached objects so it was easy just to pass in the owner as part of the Interceptor's constructor everytime I created a new session.

EX:

public class HistoryInterceptor implements Interceptor, Serializable {
private HistoryWriter history;
private boolean isHistoryOn = false;

public HistoryInterceptor(Operator admin) {
super();
history = new HistoryWriter(admin);
isHistoryOn = true;
}
.........

Now, however, I have these long sessions that are created on the fly in the servlet filter and don't have an easy way to pass in my owner to the interceptor. So I tried the following, but it seems that the instance of the Interceptor changes from my orginal instance.

In the servlet filter I do:
HibernateUtil.registerInterceptor(new HistoryInterceptor());

Then, when I'm about to save an object I make a call like this:
((HistoryInterceptor) HibernateUtil.getInterceptor()).setOwner(admin);

However the interceptor instance seems to change between when I make the call to setOwner and when the interceptor actually get's called by Hibernate. If someone see's a reason why this wouldn't work, could you point it out? Any feedback is very much appreciated!


Top
 Profile  
 
 Post subject: My Mistake
PostPosted: Tue Oct 04, 2005 9:20 am 
Newbie

Joined: Mon Oct 03, 2005 8:37 am
Posts: 6
Location: Charlotte, NC
In the event any comes across this. The problem was due to an extra "registerInterceptor" being called in one of my DAO's.

Cheers!


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.