-->
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.  [ 6 posts ] 
Author Message
 Post subject: Interceptors for currentSession doesn't work
PostPosted: Fri Oct 28, 2005 7:17 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
Hibernate version:
3.1-rc2
Mapping documents:

I modified the InterceptorTest.java in test suit as following:
public void testCollectionIntercept() {
// Session s = openSession( new CollectionInterceptor() );
new Configuration().setInterceptor( new CollectionInterceptor() );
Session s = getSessions().getCurrentSession();

I do similar in my application - in both cases Interceptors are not working.
Is it a bug of -rc2 or I do something wrong?
(I cannot use openSession as I prefer to have automatic session management with JBoss),
BTW: The same happends with EventListeners.
Regards,


Top
 Profile  
 
 Post subject: Re: Interceptors for currentSession doesn't work
PostPosted: Fri Oct 28, 2005 9:26 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
tbech wrote:
Hibernate version:
3.1-rc2
Mapping documents:

I modified the InterceptorTest.java in test suit as following:
public void testCollectionIntercept() {
// Session s = openSession( new CollectionInterceptor() );
new Configuration().setInterceptor( new CollectionInterceptor() );
Session s = getSessions().getCurrentSession();

I do similar in my application - in both cases Interceptors are not working.
Is it a bug of -rc2 or I do something wrong?
(I cannot use openSession as I prefer to have automatic session management with JBoss),
BTW: The same happends with EventListeners.
Regards,


The Configuration Object you are adding the Interceptor to isn't the same one that's being used when you call getCurrentSession().

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 4:34 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
It would be helpfull, if you paste the right code - this code I took from the documentation (so the documentation should be updated). For now I still dont know how to make interceptors working :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 8:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Please paste the url to where the Hibernate documentation uses that code as an example


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:59 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Steve,

I think he's refering to the one-line example in section 13.1. He's missing the point that the line shown is part of the overal configuration and can't be executed on it's own and separate from the overall SessionFactory configuration.

The following code is from http://www.hibernate.org/42.html with the exception of the single change to include your interceptor.

Code:
public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().setInterceptor(new YourInterceptor()).configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

sessionFactory = new Configuration().setInterceptor(new YourInterceptor()).configure().buildSessionFactory();

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 4:53 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
Thanks for help pksiv, now it works of course.
Quote:
I think he's refering to the one-line example in section 13.1. He's missing the point that the line shown is part of the overal configuration and can't be executed on it's own and separate from the overall SessionFactory configuration.

I'm fresh user, and from documentation I couldn't quess it. Also I couldn't find any sample code on the wiki/forum. Thanks for help again,


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