-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem getting JNDI resource.Eclipse.Tomcat.Hibernate tool
PostPosted: Tue Jan 20, 2009 5:08 am 
Newbie

Joined: Tue Jan 20, 2009 4:53 am
Posts: 1
Hi! I´m using Eclipse 3.4 and Hibernate tools 3.2.4 for Eclipse.
Oracle 9i. Tomcat 6 (stable).


The problem I get is about JNDI resource.


I use reverse ingeniering to generate cfg.xml and I run "Hibernate Code Generation". The results are those:

The code which has the problem:

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import static org.hibernate.criterion.Example.create;

/**
* Home object for domain model class CategoriasT.
* @see eu.malaga.dao.hibernate.CategoriasT
* @author Hibernate Tools
*/
public class CategoriasTHome {

private static final Log log = LogFactory.getLog(CategoriasTHome.class);

private final SessionFactory sessionFactory = getSessionFactory();

protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext()
.lookup("SessionFactory");
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException(
"Could not locate SessionFactory in JNDI");
}
}










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>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.password">TEMAWEB_USR</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@<myHost>:1521:dbd3</property>
<property name="hibernate.connection.username">TEMAWEB_USR</property>
<property name="hibernate.default_schema">TEMAWEB</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
<mapping resource="eu/malaga/dao/hibernate/TemasT.hbm.xml" />
<mapping resource="eu/malaga/dao/hibernate/CategoriasT.hbm.xml" />
</session-factory>
</hibernate-configuration>

Tables "Temas" and "Categorias" are completally indepent and very simple. I´m trying to use just "Categorias".

I write the following code at the jsp:

<%
CategoriasT categoria1 = new CategoriasT();
CategoriasTId categoriaId1 = new CategoriasTId();
categoriaId1.setIdAplicacion("testDavidApl_1");
categoriaId1.setIdCategoria("testDavidCat_1");
categoria1.setId(categoriaId1);

CategoriasTHome cat = new CategoriasTHome();
cat.attachClean(categoria1);
%>

The problem I get is about JNDI resource:

GRAVE: Could not locate SessionFactory in JNDI
javax.naming.NameNotFoundException: El nombre jdbc no este asociado a este contexto
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:97)
at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
at eu.malaga.dao.hibernate.CategoriasTHome.getSessionFactory(CategoriasTHome.java:27)
at eu.malaga.dao.hibernate.CategoriasTHome.<init>(CategoriasTHome.java:22)
at org.apache.jsp.prueba_jsp._jspService(prueba_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
20-ene-2009 10:03:46 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet jsp lanz� excepci�n
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at eu.malaga.dao.hibernate.CategoriasTHome.getSessionFactory(CategoriasTHome.java:30)
at eu.malaga.dao.hibernate.CategoriasTHome.<init>(CategoriasTHome.java:22)
at org.apache.jsp.prueba_jsp._jspService(prueba_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


Do I have to define any JNDI element?
How and where do I define it?
Do I have to include any library at Tomcat lib?
At the eclipse project a have include de jdbc driver.

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 10:41 am 
Newbie

Joined: Tue Feb 24, 2009 10:36 am
Posts: 1
Hi, I have a same problem with you.

But I used the Junit to test it, and use this code to get session. It works!


Code:
Configuration cfg = new Configuration();
session = cfg.configure().buildSessionFactory().openSession();


If you resolved the problem, could you please send me a message?


Top
 Profile  
 
 Post subject: Re: Problem getting JNDI resource.Eclipse.Tomcat.Hibernate tool
PostPosted: Tue Jul 31, 2012 11:46 am 
Newbie

Joined: Tue Jul 31, 2012 11:44 am
Posts: 1
Did someone could successfully solve this issue?

I have the very same issue with Eclipse auto-generated code.


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