-->
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.  [ 8 posts ] 
Author Message
 Post subject: missing something with DefaultLoadEventListener
PostPosted: Thu Feb 24, 2005 2:40 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3beta4
Mapping documents:
Code:
    <session-factory>
...      
      <listener type="load" class="com.eyrolles.sportTracker.event.SportTrackerLoadListener"/>
       
    </session-factory>

Code between sessionFactory.openSession() and session.close():
using HibernateUtil (maybe important)
Full stack trace of any exception that occurs:
that's the problem just after listener, session is closed without any exception occuring
Name and version of the database you are using:
HSQLDB
The generated SQL (show_sql=true):
not important
Debug level Hibernate log excerpt:




Code:
public class SportTrackerLoadListener extends DefaultLoadEventListener {
    public Object onLoad(LoadEvent event, LoadEventListener.LoadType loadType)
    throws HibernateException {
        System.out.println("testEvent");
        Object o = null;
        try{
            System.out.println("eventTest");
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return super.onLoad(event, loadType);
    }
   
}


Code:
    public void testJoin() throws Exception  {
        initData();

        Session session = HibernateUtil.getSession();
        Transaction tx=null;
        try {
            tx = session.beginTransaction();
            // here session is still connected
            // the listener is activated, i can see my println in the console but just after, the debugger jump into the finally block ;(
            EhancedTeam t = (EhancedTeam)session.get(EhancedTeam.class,new Long(1));

            System.out.println(t.getCoachName());
            tx.commit();
        }
        catch (Exception e) {
            e.printStackTrace();
            if (tx!=null) tx.rollback();   
            throw e;
        }
        finally {
            session.close();
            System.out.println
        }
    }



why, when using my listener, the finally block is reached without intercepting any exception?

I must miss something, or done something wrong... but i don't see what...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What do you mean by " the finally block is reached without intercepting any exception?"? Thats the thing about a finally block, its entered always, regardless if there is an exception or not ... or do I misunderstand you?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
yes of course but these lines are not executed
Code:
            System.out.println(t.getCoachName());
            tx.commit();

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:24 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
eheh, i knew an exception occured but my test class was bad:
Code:
   protected void runTest() throws Throwable {
      try {
         System.out.println("Running test...");
         super.runTest();
      } catch (Throwable e) {
            //e.printStackTrace();
         HibernateUtil.rollbackTransaction();
         throw e;
      } finally{
         HibernateUtil.closeSession();
      }
   }


i've just added a printstacktrace and here is the exception:
Code:
java.lang.NoSuchMethodError: org.hibernate.event.LoadEvent.getSource()Lorg/hibernate/event/SessionEventSource;
   at org.hibernate.event.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:56)
   at com.eyrolles.sportTracker.event.SportTrackerLoadListener.onLoad(SportTrackerLoadListener.java:25)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
   at com.eyrolles.sportTracker.test.JoinTest.testJoin(JoinTest.java:34)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at com.eyrolles.sportTracker.test.TestCase.runTest(TestCase.java:18)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)


i've just copied/pasted the exemple i've found in the reference guide, i've surely done an error.... my bad ;(

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Are you using the source, or the actuall beta bundle?

events used to obtain the session by a method named getSource(), which was later renamed to getSession().

Somehow you just have some class-version incompatibilities.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:34 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hum, i've updated from cvs this morning and made a homebuild.... i really think i've the latest versions

impossible for me to find org.hibernate.event.DefaultLoadEventListener in my H3 eclipse project...
i'm going to clean all this and start again, i'll tell you where was my problem tomorrow

see you

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:40 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
ok forget all this, my eclipse was down, not doing well my import, it was importing org.hibernate.event.DefaultLoadEventListener instead of org.hibernate.event.def.DefaultLoadEventListener

all is running fine now....

thanks guys (and no thanks eclipse!)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
They also changed packages. There is a new package org.hibernate.event.def which contains all the default stuff.


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