-->
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.  [ 9 posts ] 
Author Message
 Post subject: help-- hibernate JNDI lookup call returns null
PostPosted: Fri Oct 21, 2005 6:27 am 
Newbie

Joined: Mon Oct 17, 2005 11:32 am
Posts: 8
Location: India
hi,
i have been able to create a JNDI sevice for hibernate but when i try and use it in my web App using the lookup() it returns an error.. pls help

this is my hibernateservice.xml
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="hiber:name=HibernateUtil">
<attribute name="DatasourceName">java:/PostgresDS</attribute>
<attribute name="Dialect">
org.hibernate.dialect.PostgreSQLDialect
</attribute>
<attribute name="SessionFactoryName">
java:/hiber/HibernateUtil
</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
</mbean>
</server>

this is the code i am trying

InitialContext ctx = new InitialContext();
SessionFactory factory = (SessionFactory)ctx.lookup("java:/hiber/HibernateUtil");

Session session = factory.openSession()

Transaction tx = session.beginTransaction();
result = session.createQuery("from Event").list();
tx.commit();
session.close();

it returns a null pointer exception.. the stack trace from the log file is as follows...

2005-10-21 15:52:02,383 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] initializing class SessionFactoryObjectFactory
2005-10-21 15:52:02,403 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: hiber/HibernateUtil
2005-10-21 15:52:02,413 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=2c9048960712b253010712b25d380000
2005-10-21 15:52:02,413 WARN [org.hibernate.impl.SessionFactoryObjectFactory] Not found: 2c9048960712b253010712b25d380000
2005-10-21 15:52:02,413 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] {}
2005-10-21 15:52:02,433 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/testJNDIHibernate].[listEvents]] Servlet.service() for servlet listEvents threw exception
java.lang.NullPointerException
at hiber.listEvents.doPost(listEvents.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)

i am not able to figure out why its not able to lookup for the JNDI name


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 7:13 am 
Newbie

Joined: Wed Oct 05, 2005 1:20 pm
Posts: 15
Location: Russia Izhevsk
Use
http://localhost:8080/jmx-console/
jboss
service=JNDIView
list()

in order to examine your JNDI tree.

Also you can try
Code:
ctx.lookup("java:comp/env/hiber/HibernateUtil");


--
Andrey Grebnev
http://www.jroller.com/page/agrebnev


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 7:29 am 
Newbie

Joined: Mon Oct 17, 2005 11:32 am
Posts: 8
Location: India
hi,
thanks for replying back ... it is showing in the jndi-tree.. and i am using jBoss4.0.3 AS and hence i dont think
ctx.lookup("java:comp/env/hiber/HibernateUtil");
will be able to locate it. i had also mapped a datasource (PostgresDS) and am able to access is using "java:/PostgresDS".. is there anything else i am missing.. or would u like to see any other part of my code...

rgds
Amit


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 11:49 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Class Loaders.

Hibernate uses an Object Factory for JNDI that stores the Hibernate Session Factory by a UID. When you look up the Session Factory, it takes the UID of the lookup, and tries to find the matching session factory in it's internal cache.

If you initialise the session factory in the same class loader, then you'll have a Session Factory Object Factory that has the UID -> Session Factory cached.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 7:02 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Hi,

-----------------------
Hibernate: 2.1.4
Oracle: 9i
Jboss: 3.2.6
-----------------------

I´m using lookup to get the jndi.

At this moment didn´t have any problem, but now
the SessionFactory, sometimes, is missing (null), and I need
restart the application server.

Code:
            InitialContext ctx = new InitialContext();
            factory = (SessionFactory) ctx.lookup(jndiName);


What can be occurring?

thanks

[]´s

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 7:33 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Check that it's still bound using the JNDIView utility in JBoss - go to the JMX Console, find the JNDIView MBean, and on it's detail page invoke list method.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 7:56 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
Now it´s OK, It´s bound.
but sometimes, it´s missing... :-(

thanxs

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:06 am 
Senior
Senior

Joined: Wed Sep 24, 2003 3:01 pm
Posts: 158
Location: Bragan�a Paulista - Brasil
What is it correct?

1- lookup only one time and set the SessionFactory to a context for example; or
2- lookup at each use.

_________________
Tads


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 9:03 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
Depends on how your code is working.

Using EJBs we look the Session Factory up at the start of the call, get the current session, do the work in there and return. Never has a problem, but we're using Hibernate 3 and JBoss 4.

Post logs from those times that the session factory is missing.


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