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!