- This topic has 6 replies, 5 voices, and was last updated 18 years ago by Haris Peco.
-
AuthorPosts
-
closec1MemberI’m new to hibernate and I’m trying to use the JNDI DAO that is generated by myeclipse. I can’t seem to setup hibernate correctly to use WebLogic JNDI. Please help.
my 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”><!– Generated by MyEclipse Hibernate Tools. –>
<hibernate-configuration><session-factory>
<property name=”dialect”>org.hibernate.dialect.OracleDialect</property>
<property name=”jndi.url”>t3://localhost:7001</property>
<property name=”jndi.class”>weblogic.jndi.WLInitialContextFactory</property>
<property name=”connection.datasource”>orcl-milemarker-jdbc</property>
<mapping resource=”com/autotrader/milemarkers/reports/Reports.hbm.xml” /></session-factory>
</hibernate-configuration>
——————I keep getting the error below:
Error 500–Internal Server Error
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at com.autotrader.milemarkers.reports.ReportsDAO.getSessionFactory(ReportsDAO.java:27)
at com.autotrader.milemarkers.reports.ReportsDAO.(ReportsDAO.java:20)
at jsp_servlet._jsp.__myjsp._jspService(__myjsp.java:138)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)my ReportsDAO.java
————————
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 org.hibernate.criterion.Example;Public class ReportsDAO {
private static final Log log = LogFactory.getLog(ReportsDAO.class);
private final SessionFactory sessionFactory = getSessionFactory();
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup(“orcl-milemarker-jdbc”);
} catch (Exception e) {
log.error(“Could not locate SessionFactory in JNDI”, e);
throw new IllegalStateException(“Could not locate SessionFactory in JNDI”);
}
}
public Reports findById( java.lang.Long id) {
log.debug(“getting Reports instance with id: ” + id);
try {
Reports instance = (Reports) sessionFactory.getCurrentSession()
.get(“com.autotrader.milemarkers.reports.Reports”, id);
return instance;
} catch (RuntimeException re) {
log.error(“get failed”, re);
throw re;
}
}
}
Riyad KallaMemberDid you actually go into the WebLogic administration console and setup the JNDI data source to point at your database?
closec1MemberYes the datasource was setup previously. I’m trying to convert the application to use hibernate. I know this probably isn’t the correct forum for this issue but I’m stuck and just shooting in the dark for any answers.
Riyad KallaMemberYour JNDI url doesn’t make sense… if your app server is hosting up your data source under JNDI, then it will look something like java:/comp/env/jdbc/weblogic or something like that…
Have a look here for more help: http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-optional-jndi
lambo82669Memberyou must call “new Configuration().configure().buildSessionFactory()” in order to have the sessionfactory register itself with the weblogic jndi context.
jguatemalaMemberHello, tell me please Where do you call “new Configuration().configure().buildSessionFactory()” in the DAO class or HibernateSessionFactory
Haris PecoMemberjguatemala,
It is called :
– HibernateSessionFactory#rebuildSessionFactory()
– in Spring DAO it is called with Spring – Spring have session factory bean
– in Base DAO it is called in BaseHibernateDAO (call HibernateSessionFactory)
– in JNDI DAO you have to make session factory JNIDI in your application serverRegards,
-
AuthorPosts