JBoss JNDI - Hibernate sessionfactory
dbd1979 May 25, 2011 1:58 PMI have an EJB.ear file which contains a jar for Hibernate related code. Once EJB.ear gets deployed into JBoss, I am sending a transaction to session bean which invokes Hibernate code and loads hibernate.cfg.xml.
However lookup of hibernate session factory throws a not found error. I listed the JNDI list using jmx-console and i dont see Hibernate session factory registered in JNDI.
Should the hibernate cfg.xml be deployed in a different manner (possibly outside of jar) for hibernate session factory to be registered in JNDI ? Is it not possible to register objects in JNDI from within application code/configuration after JBoss has started ?
12:29:14,064 INFO [Configuration] Configuration resource: managed-hibernate.cfg.xml 12:29:14,095 INFO [Configuration] Reading mappings from resource : IteratorInfo.hbm.xml 12:29:15,220 INFO [HbmBinder] Mapping class: com.hibernate.test.IteratorInfo -> ITERATORINFO 12:29:15,392 INFO [Configuration] Configured SessionFactory: java:/HibernatorSessionFactory
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="java:/HibernatorSessionFactory"> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="show_sql">true</property> <property name="hibernate.connection.datasource">java:/OracleDS</property>
Code to lookup:
InitialContext ctx = new InitialContext(); sessionFactory = (SessionFactory)ctx.lookup("java:/HibernatorSessionFactory");
Error:
12:49:35,322 ERROR [STDERR] javax.naming.NameNotFoundException: java:/HibernatorSessionFactory not bound 12:49:35,322 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:771) 12:49:35,322 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:779) 12:49:35,322 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:785) 12:49:35,322 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:443) 12:49:35,322 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726) 12:49:35,322 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) 12:49:35,322 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)