-->
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.  [ 4 posts ] 
Author Message
 Post subject: errors in the tutorial in the reference documentation
PostPosted: Thu Apr 13, 2006 8:40 pm 
Newbie

Joined: Thu Apr 13, 2006 8:29 pm
Posts: 3
Hi, I'm not sure if this is the correct place to be posting these discrepancies, but hopefully someone who can fix them will notice and get around to updating the tutorial.

URL:
http://www.hibernate.org/hib_docs/v3/re ... orial.html

the EventManager class described in the tutorial makes a call to session.getTransaction() where no such method exists.

It looks like getTransaction has been replaced by returning a transaction from session.beginTransaction() making the correct code:

Code:
    private void createAndStoreEvent(final String title, final Date theDate) {

        final Session session = HibernateUtil.getSessionFactory().getCurrentSession();

        final Transaction transaction = session.beginTransaction();

        final Event theEvent = new Event();
        theEvent.setTitle(title);
        theEvent.setDate(theDate);

        session.save(theEvent);

        transaction.commit();
    }


That allows the code to compile, however I am having trouble at runtime when hibernate goes to save the Event instance, and I'm fairly certain it's because I'm missing a piece of configuration in hibernate.cfg.xml

The stack trace is as follows:
Code:
Exception in thread "main" org.hibernate.HibernateException: No TransactionManagerLookup specified
   at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:503)
   at events.EventManager.createAndStoreEvent(EventManager.java:26)
   at events.EventManager.main(EventManager.java:18)


The only slight variation I'm taking from the tutorial is in using MySQL instead of HS, however I'm convinced that's not the issue as there's no problem initialising Hibernate (which involves establishing the connection and running the CREATE statements).


I'll probably find the Transaction configuration by myself, I thought I'd post the issues here somewhere so they could be fixed to make things easier for the next people to use the tutorial.


Last edited by travis on Thu Apr 13, 2006 10:57 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:37 pm 
Newbie

Joined: Thu Apr 13, 2006 8:29 pm
Posts: 3
Confirmed:

vamp boy posted the solution in thread http://forums.hibernate.org/viewtopic.p ... 4e5f1484ed

Quote:
getCurrentSession is only available within a JTA environment. Use openSession instead.


So there were two problems with the tutorial. firstly the getTransaction() secondly either the use of getCurrentSession() or the use of thread in the configuration.

If anyone can point me to some documentation so that I might understand why getCurrentSession() is not available for thread configuration I would appreciate it. The API doesn't seem to indicate it (although it does mention JTA in the method description)

The final working code ended up:

Code:
   private void createAndStoreEvent(final String title, final Date theDate)
{
        final SessionFactory factory = HibernateUtil.getSessionFactory();
        final Session session = factory.openSession();

        final Transaction transaction = session.beginTransaction();

        final Event theEvent = new Event();
        theEvent.setTitle(title);
        theEvent.setDate(theDate);

        session.save(theEvent);

        transaction.commit();
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 14, 2006 4:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is no problem with the tutorial. You guys are wrong, read it again. And use the source code that comes with it and runs just fine.

http://hibernate.org/hib_docs/v3/api/or ... ansaction()

http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 9:32 pm 
Newbie

Joined: Thu Apr 13, 2006 8:29 pm
Posts: 3
Quote:
There is no problem with the tutorial. You guys are wrong, read it again. And use the source code that comes with it and runs just fine.


Interesting, then I can confirm that MyEclipse 4.0.3 which claims to bundle Hibernate 3 does not support the api you linked to.

I'll raise it in the MyEclipse forums


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