-->
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: Cannot get a session Factory using JNDI in a J2EE Server
PostPosted: Wed Sep 27, 2006 4:02 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 5:46 am
Posts: 21
Location: india
Hi
I am in big trouble folks. i am not able to configure getting SessionFactory from JNDI . Please help me details about the cfg and error stackTrace are mentioned below.


This is my cfg file:
<?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="SessionFactory">
<property name="connection.pool_size">1</property>
<property name="hibernate.session_factory_name">SessionFactory</property>
<!-- <property name="hibernate.jndi.url"></property>
<property name="hibernate.jndi.class"></property> -->

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto"></property>

<mapping resource="com/ocr/wms/hib/mapping/HiberTableMapping.hbm.xml" />
<mapping resource="com/ocr/wms/hib/mapping/HiberTableSecondMapping.hbm.xml" />
<mapping resource="com/ocr/wms/hib/mapping/HibernateTableCompositeMapping.hbm.xml" />

</session-factory>

</hibernate-configuration>



Code calling Session factory using JNDI lookup
try {

Context ctx = new InitialContext();
SessionFactory sesionf = (SessionFactory) ctx.lookup("SessionFactory");
Session session = sesionf.getCurrentSession();
session.beginTransaction();
query="from HiberTableSecond hts where hts.serialid = any(select ht.id from HiberTable ht)";
List sourcelist = session.createQuery(query).list();
return sourcelist;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}



This is the Full stack trace of the exception that occured:

13:26:57,629 ERROR [STDERR] javax.naming.NameNotFoundException: SessionFactory not bound
13:26:57,629 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
13:26:57,629 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
13:26:57,645 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
13:26:57,645 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
13:26:57,645 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:445)
13:26:57,645 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:429)
13:26:57,645 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:347)
13:26:57,645 ERROR [STDERR] at com.ocr.wms.manager.FacadeWmsManagerBean.selectDataSubQuery(FacadeWmsManagerBean.java:113)
13:26:57,645 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13:26:57,645 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
13:26:57,645 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
13:26:57,645 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer
.java:664)
13:26:57,645 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInter
ceptor.java:147)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInte
rceptor.java:77)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)
13:26:57,645 ERROR [STDERR] at org.jboss.ejb.Container.invoke(Container.java:705)
13:26:57,645 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
13:26:57,645 ERROR [STDERR] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:364)
13:26:57,645 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13:26:57,645 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
13:26:57,645 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
13:26:57,645 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
13:26:57,645 ERROR [STDERR] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
13:26:57,645 ERROR [STDERR] at sun.rmi.transport.Transport$1.run(Transport.java:148)
13:26:57,645 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
13:26:57,645 ERROR [STDERR] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
13:26:57,645 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
13:26:57,645 ERROR [STDERR] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
13:26:57,645 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)


Please help me. I have to imlement it in both websphere and jboss Application Server.

Joseph C

_________________
JosephC


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 10:43 am 
Newbie

Joined: Wed Nov 23, 2005 5:01 am
Posts: 15
Hi,

Have you bind the SessionFactory into JNDI ? You have to bind the SessionFactory first to the JNDI.

Into the jboss server you can do this using the Hibernate MBean service. This service take care of building your Configuration and SessionFactory object and also to bind the SessionFactory into the server JNDI.

I guess into the WebSphere is also some kind of process but I am not very sure about this.
I am using JBoss.

I hope this help.
Calin.

_________________
I hope this help.
Calin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 4:18 am 
Newbie

Joined: Thu Nov 17, 2005 10:46 am
Posts: 3
The hibernate configuration file must be loaded first. So have that in the static block of the class or have a start up class with the below.

For say in HibernateUtil.java have the below

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
new Configuration().configure("com/../hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 6:47 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 5:46 am
Posts: 21
Location: india
thanks guys for the tips.

_________________
JosephC


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.