-->
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: Help setting up getCurrentSession
PostPosted: Thu Jul 07, 2005 1:54 pm 
Newbie

Joined: Thu Jul 07, 2005 1:47 pm
Posts: 6
Ok I've tried a million things to getCurrentSession, and still cannot seem to get it to work.

I am using JBoss 4.02 and Hibernate3.


Here is the exception:

Code:
java.lang.NullPointerException
        at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:509)
        at com.atwcorp.trustedapp.domain.util.HibernateUtil.getSession(HibernateUtil.java:150)



Here is my hibernate-service.xml:

Code:
<server>
   <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
      <attribute name="DatasourceName">java:/MyAPP</attribute>
      <attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
      <attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
      <attribute name="ShowSqlEnabled">true</attribute>
        <attribute name="Hbm2ddlAuto">create-drop</attribute>
   </mbean>
</server>



Here is the code to get the session which I put in my HibernateUtil class:

Code:
   public static Session getSession {
         SessionFactory sessions = null;
      try {
         Context ctx = new InitialContext();
         String jndiName = "java:hibernate/SessionFactory";
         sessions = (SessionFactory)ctx.lookup(jndiName);
      } catch (NamingException ex) {
         //throw new HibernateException(ex);
      }
      return sessions.getCurrentSession();
   }


What am I doing wrong? Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 9:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
i would assume that you :
1) do not have a transaction in effect when you call getCurrentSession()
2) are using 3.0.1 which reported this s a NPE. Newer versions give a more explicit error


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.