-->
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.  [ 7 posts ] 
Author Message
 Post subject: SessionFactory from JNDI is "null"
PostPosted: Sat Jul 25, 2009 3:27 pm 
Newbie

Joined: Sat Jul 25, 2009 3:06 pm
Posts: 4
Hi, just as the topic says, when I fish out my SessionFactory from JNDI it's coming up null.

Here's my config/code/what I'm doing, etc.

First, we configure Hibernate right at the startup of JBoss using a datasource defined there:

Code:
<local-tx-datasource>
   <jndi-name>ucentive/production/PostgresDS</jndi-name>
   <connection-url>jdbc:postgresql://<url-to-db></connection-url>
   <driver-class>org.postgresql.Driver</driver-class>
   <user-name><username></user-name>
   <password><password></password>
</local-tx-datasource>


Here's the top of my hibernate.cfg.xml file:

Code:
<hibernate-configuration>
   <session-factory>

      <!-- Begin Properties -->
      <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <property name="hibernate.jdbc.batch_size">50</property>
      <property name="current_session_context_class">thread</property>
      <property name="hibernate.show_sql">false</property>
      <property name="hibernate.format_sql">false</property>
      <property name="connection.autocommit">true</property>
      <property name="hibernate.session_factory_name">java:/ucentive/hibernate/SessionFactory</property>
      
      ...


Here's how we init it:

Code:
private static SessionFactory sessionFactory;

...

Configuration config = new AnnotationConfiguration();
config.mergeProperties(properties);

config.setInterceptor(new DateInterceptor());
SaveOrUpdateEventListener[] saveOrUpdateEventListeners = { new RefNumListener(), new DefaultSaveOrUpdateEventListener() };
config.getEventListeners().setSaveEventListeners(saveOrUpdateEventListeners);

config.configure("/hibernate.cfg.xml");

sessionFactory = config.buildSessionFactory();


Those properties I'm merging are these:

Code:
hibernate.connection.datasource = <that datasource path defined above>


Now, this -does- work because all of the servlets that use that static sessionFactory to make a new session are able to just fine. Everything works great. The problem comes in when something else tries to get it out of JNDI.

Here's how I try to look it up inside the container:

Code:
InitialContext context = new InitialContext();

SessionFactory sf = (SessionFactory) context.lookup("java:/ucentive/hibernate/SessionFactory");


What happens is sf is null. It can find it just fine. It's just that it seems to have been inserted as null to begin with.

Here's how we look it up remotely:

Code:
...

properties.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.setProperty("java.naming.provider.url", "localhost:1099");
properties.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");       

...

InitialContext context = new InitialContext(properties);
SessionFactory sf = (SessionFactory) context.lookup("java:/ucentive/hibernate/SessionFactory");


Again, it finds it just fine ... it just comes out null.

Any help is appreciated!


Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Sun Jul 26, 2009 7:45 pm 
Newbie

Joined: Fri Mar 21, 2008 11:35 am
Posts: 10
Could you maybe provide a bit more information?

Are you using an app server, if so which one?

When you see hibernate start up in your log files, do you see the message about the session factory binding to JNDI?


Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Mon Jul 27, 2009 11:01 am 
Newbie

Joined: Sat Jul 25, 2009 3:06 pm
Posts: 4
Appserver is JBoss (mentioned above). I did turn on very fine-grain logging for Hibernate and did see this:

Code:
1225 [main] INFO  org.hibernate.cfg.Configuration:1541 - Configured SessionFactory: null


To what, then, do I change my config so that it -does- work?

Thanks in advance!


Last edited by afrederico on Mon Jul 27, 2009 11:02 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Mon Jul 27, 2009 11:02 am 
Newbie

Joined: Sat Jul 25, 2009 3:06 pm
Posts: 4
Oops, looking at the end of the logs I see this:

Code:
17943 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
17954 [main] DEBUG org.hibernate.impl.SessionFactoryObjectFactory:76 - registered: ff80808122bcb8e70122bcb904610000 (java:/ucentive/hibernate/SessionFactory)
17955 [main] INFO  org.hibernate.impl.SessionFactoryObjectFactory:86 - Factory name: java:/ucentive/hibernate/SessionFactory
17961 [main] INFO  org.hibernate.util.NamingHelper:26 - JNDI InitialContext properties:{}
17962 [main] DEBUG org.hibernate.util.NamingHelper:48 - binding: java:/ucentive/hibernate/SessionFactory
17976 [main] DEBUG org.hibernate.impl.SessionFactoryImpl:594 - Returning a Reference to the SessionFactory


Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Mon Jul 27, 2009 11:50 am 
Newbie

Joined: Sat Jul 25, 2009 3:06 pm
Posts: 4
Oh, one more thing to add: I'm trying to access this from a different EAR file than it was originally started in.


Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Fri Sep 25, 2009 7:46 pm 
Newbie

Joined: Sat Nov 22, 2008 1:35 pm
Posts: 7
Have you been able to figure this out ? I'm having a very similar problem and have seen no resolution on any message board out there. I'm using JBOSS 5.1.0, Hibernate 3.3.1, and Netbeans 6.7.1. I see the following message in the server logs indicating that the SessionFactory was successfully started and bound to the JNDI name that I specified:
Code:
18:22:12,557 INFO  [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/GGGoMobileSessionFactory]


However, when I try to access the SessionFactory through a JNDI lookup using the code below, I get a null value:
Code:
session_factory = (SessionFactory) ctx.lookup("java:/hibernate/GGGoMobileSessionFactory");


I have been stuck on this issue for days and tried every possible solution that has come to mind and I'm making no progress. Would really appreciate some help. Thanks.


Top
 Profile  
 
 Post subject: Re: SessionFactory from JNDI is "null"
PostPosted: Fri Sep 23, 2011 12:45 pm 
Newbie

Joined: Fri Sep 23, 2011 12:34 pm
Posts: 1
I'm having the same issue. JNDI SessionFactory always returns null? Based on log sessionfactory was bound successfully to JNDI with as "java:/hibernate/SessionFactory"! There got a be a solution to this. Any help will be highly appreciated. I'm in JBOSS 4.2.3.

Regards.
MO


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