-->
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: sessionFactory.getCurrentSession() problem
PostPosted: Sat Jul 16, 2005 8:30 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:36 am
Posts: 29
Location: Houston, TX
Hibernate version: 3.0.2

I recently switched a major project from ejb 2.1 to hibernate 3.0 with great results. Now I am trying to get this set up for a very simple web app. I use sessionFactory.getCurrentSession(), but I am receiving a null pointer error. If I use sessionFactory.getOpenSession() everything works as expected. I cannot find the difference in the setup in my two projects. Any help would be appreciated. If this is not enough information I can switch my code back and generate a stack trace. I tried to get the source, but sourceforge is not working currently.

_________________
Thank you for your time,

Jason Long
CEO and Chief Software Engineer
BS Physics, MS Chemical Engineering
http://www.supernovasoftware.com
HJBUG Founder and President
http://www.hjbug.com


Top
 Profile  
 
 Post subject: Re: sessionFactory.getCurrentSession() problem
PostPosted: Sat Jul 16, 2005 8:58 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
§upernova§oftware wrote:
Hibernate version: 3.0.2

I recently switched a major project from ejb 2.1 to hibernate 3.0 with great results. Now I am trying to get this set up for a very simple web app. I use sessionFactory.getCurrentSession(), but I am receiving a null pointer error. If I use sessionFactory.getOpenSession() everything works as expected. I cannot find the difference in the setup in my two projects. Any help would be appreciated. If this is not enough information I can switch my code back and generate a stack trace. I tried to get the source, but sourceforge is not working currently.


getCurrentSession() only works in a managed environment - an Application Server.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 16, 2005 9:38 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:36 am
Posts: 29
Location: Houston, TX
I am using a manage enviroment, but this must not be set up property in my new project. I am using JBoss 4.0.2 with pojo annotations.

Here is the code I am using:

Code:
    public Session getCurrentSession() {
        Session hsession = null;
        try {
          InitialContext ctx = new InitialContext();
          SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory/pipetracker");
          hsession = factory.getCurrentSession();
        } catch (NamingException ne) {
          ne.printStackTrace(); 
        }
        return hsession;
    }

_________________
Thank you for your time,

Jason Long
CEO and Chief Software Engineer
BS Physics, MS Chemical Engineering
http://www.supernovasoftware.com
HJBUG Founder and President
http://www.hjbug.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 16, 2005 11:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Are you *certain* that there is a JTA transaction started *before* you make a call to getCurrentSession()?


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.