-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to use JNDI of Sun Java Application server 8.1?
PostPosted: Mon Apr 23, 2007 9:55 am 
Newbie

Joined: Mon Apr 23, 2007 9:22 am
Posts: 6
Hi,


I am using Java 1.5 for Web Application. I want to use JNDI configuration in my Hibernate Application. I am using Sun Java Application server to host my web application. I have done all configuration to use JNDi in hibernate but it throws SessionFactory could not bound exception. ths code snippest is as follows..please help to sort out that problem.. And one more thing I am using remote SQL Server2001 as database.

[b]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:comp/env/hibernate/SessionFactory">
<property name="hibernate.connection.datasource">jdbc/jndidemo</property>

<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">0</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">false</property>

<mapping resource="com/demo/jndi/PMI.hbm.xml"/>
</session-factory>

</hibernate-configuration>

HibernateUtil.java


package com.demo.jndi ;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

/**
* @netbeans.hibernate.util
*/
public class PMIUtil
{
private static Log log = LogFactory.getLog(PMIUtil.class);

private static SessionFactory sessionFactory;

private static SessionFactory getSessionFactory()
{
try
{
if (sessionFactory == null) {
Configuration configuration = new Configuration();
// load all beans
InputStream is = PMIUtil.class.getResourceAsStream("hibernateBeans.lst");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line ;
while ((line = reader.readLine()) != null) {
configuration.addResource(line);
}
Properties properties = new Properties();
properties.load(PMIUtil.class.getResourceAsStream("hibernate.properties"));
configuration.setProperties(properties);
sessionFactory = configuration.buildSessionFactory();
}
}
catch (Throwable ex)
{
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
return sessionFactory;
}

public static final ThreadLocal session = new ThreadLocal();


public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
s = getSessionFactory().openSession();
session.set(s);
}
return s;
}


public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}

}


This code throws en exception that SessionFactory could not bound when i deploy it in application server.

Please reply me.

Thanks,
Bipin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 12:58 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Let's see the stack trace.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 3:09 am 
Newbie

Joined: Mon Apr 23, 2007 9:22 am
Posts: 6
Hi,

This is the server stack trace that i am getting.

Code:
Servlet.service() for servlet JNDIServlet threw exception
java.lang.ExceptionInInitializerError
   at com.demo.jndi.PMIUtil.getSessionFactory(PMIUtil.java:51)
   at com.demo.jndi.PMIUtil.currentSession(PMIUtil.java:62)
   at com.demo.jndi.JNDIServlet.processRequest(JNDIServlet.java:45)
   at com.demo.jndi.JNDIServlet.doGet(JNDIServlet.java:83)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
   at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
   at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
   at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
   at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
   at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
   at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
   at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
   at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
   at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
   at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
   at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
   at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
   at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
   at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
   at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
   at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
   at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:422)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   at com.demo.jndi.PMIUtil.getSessionFactory(PMIUtil.java:45)
   ... 29 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 3:21 am 
Newbie

Joined: Mon Apr 23, 2007 9:22 am
Posts: 6
Hi,

This is another stack trace that, I am getting when using NetBeans.

Code:
INFO  - Reading mappings from resource: com/demo/jndi/PMI.hbm.xml
INFO  - Reading mappings from resource: com/demo/jndi/PMI.hbm.xml
INFO  - Mapping class: com.demo.jndi.PMI -> PMI
WARN  - No connection properties specified - the user must supply JDBC connections
ERROR - Initial SessionFactory creation failed.
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
        at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
        at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
        at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:422)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at com.demo.jndi.PMIUtil.getSessionFactory(PMIUtil.java:45)
        at com.demo.jndi.PMIUtil.currentSession(PMIUtil.java:62)
        at com.demo.jndi.JNDIServlet.processRequest(JNDIServlet.java:45)
        at com.demo.jndi.JNDIServlet.doGet(JNDIServlet.java:83)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
        at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
StandardWrapperValve[JNDIServlet]: Servlet.service() for servlet JNDIServlet threw exception
java.lang.ExceptionInInitializerError
        at com.demo.jndi.PMIUtil.getSessionFactory(PMIUtil.java:51)
        at com.demo.jndi.PMIUtil.currentSession(PMIUtil.java:62)
        at com.demo.jndi.JNDIServlet.processRequest(JNDIServlet.java:45)
        at com.demo.jndi.JNDIServlet.doGet(JNDIServlet.java:83)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
        at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
        at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
        at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
        at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
        at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:422)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at com.demo.jndi.PMIUtil.getSessionFactory(PMIUtil.java:45)
        ... 29 more

     Please reply.

Thanks in advanced.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 8:51 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Can you change dialect to hibernate.dialect and see what happens.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 9:37 am 
Newbie

Joined: Mon Apr 23, 2007 9:22 am
Posts: 6
HI,
Thanks for reply. I got my solutions. There is problem in JNDI configuration at server side. I have put some illegal parameter in JNDI.

Now it works,

Cheers,


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