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: using mysql...but JNDI is generated??
PostPosted: Tue May 02, 2006 10:09 pm 
Newbie

Joined: Tue May 02, 2006 9:56 pm
Posts: 6
Hello,
Im having problem with hibernate tools. I have my hibernate.cfg set for a mysql database, during the reverse engineering process it connected to teh database find and i was able to generate my hibernate.revenge file just fine. but then when i do code generation for DAO java files, it generates code for JNDI connections! this is the method that is used for all the DAO files
Code:
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");
      }
   }


so then when i deploy my app i get stack trace that is outputted at the bottom. Here is my hibernate files...
Code:

<?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.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/online_bank</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>
 


Code:
  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <table-filter match-catalog="online_bank" match-name="account_type"/>
  <table-filter match-catalog="online_bank" match-name="admin"/>
  <table-filter match-catalog="online_bank" match-name="admin_login"/>
  <table-filter match-catalog="online_bank" match-name="admin_passwords"/>
  <table-filter match-catalog="online_bank" match-name="cust_login"/>
  <table-filter match-catalog="online_bank" match-name="cust_passwords"/>
  <table-filter match-catalog="online_bank" match-name="customer"/>
  <table-filter match-catalog="online_bank" match-name="invalid_admin_login"/>
  <table-filter match-catalog="online_bank" match-name="invalid_cust_login"/>
  <table-filter match-catalog="online_bank" match-name="transaction_type"/>
  <table-filter match-catalog="online_bank" match-name="transactions"/>
</hibernate-reverse-engineering>


Hibernate version:3

Full stack trace of any exception that occurs:
2006-05-02 18:41:45,062 [http-8080-Processor24] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AccountTypeDAO' defined in ServletContext resource [/WEB-INF/classes/springDAO.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.FatalBeanException: Could not instantiate class [bank.online.dao.hibernate.onlinebank.AccountTypeDAO]; constructor threw exception; nested exception is java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
org.springframework.beans.FatalBeanException: Could not instantiate class [bank.online.dao.hibernate.onlinebank.AccountTypeDAO]; constructor threw exception; nested exception is java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at bank.online.dao.hibernate.onlinebank.AccountTypeDAO.getSessionFactory(AccountTypeDAO.java:31)
at bank.online.dao.hibernate.onlinebank.AccountTypeDAO.<init>(AccountTypeDAO.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:73)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:50)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:48)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:193)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:240)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:236)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:304)
at org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3831)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4323)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:926)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:653)
at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:401)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:712)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)


Name and version of the database you are using:Mysql 5.0.20

Does anyone have any ideas on why this is happening?
Thanks
-Ray[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 3:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
maybe because the DAO generation assumes you are putting your sessionfactory into a standard java locator api ? :)

Using a drivermanaged connection does not exclude usage of jndi for the sessionfactory. You can have hibernate do it automatically by specifying a name in the hibernate.cfg.xml on the session-factory element.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 11:28 am 
Newbie

Joined: Tue May 02, 2006 9:56 pm
Posts: 6
Thanks for the reply max, but I ended just using a differnet tool. For future reference though I would like to figure this out. So i took a look at the documentation and in an example I found these parameters being used

Code:
<!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</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">create</property>

        <mapping resource="events/Event.hbm.xml"/>


are those the paramters that you were talking about that had to be filled in? sorry for the ignorance but im still a slight noob to this stuff.
Thanks
-Ray


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 1:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
which other tool ? :)


...and I don't understand you other question ? Is it just to hear if that is the settings you need ? if yes, then i always refer to the 1 chapter tutorial in the documentation (+ the configuraiton chapter) where that is explained once and for all.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 2:18 pm 
Newbie

Joined: Tue May 02, 2006 9:56 pm
Posts: 6
I used MyEclipse to generate all the files for me (mappings, DAO, domains, etc...). We a license at work and it works pretty good....but since this is a home project i just downloaded the trial version since i couldnt get hibernateTools working properly.

anyways Ill take alook at that chapter you referenced and give it another shot.

Thanks
-Ray


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 2:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
fun since myeclipse uses the hibernate tools for this stuff ;)

If you could tell me more precisly what was going wrong then I can fix it; but need to know about it to fix it. thanks.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 4:28 pm 
Newbie

Joined: Tue May 02, 2006 9:56 pm
Posts: 6
lol i guess myeclipse is doing something im not.

anyways the situation is this. I created a database called online_bank. I configured the schema and everything. So I used the hibernateTools wizards to created my hibernate.cfg and hibernate.reveng files. The files that these wizards generated were the files I listed in my first post.
So then I ran the code generation function to generate my mappings, domains, DAO's. The generator produced the DAO code that I listed above, which references a JNDI connection and not a MySQL connection.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the dao does not need a *connection* it is looking for a *sessionfactory*

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 10:50 pm 
Newbie

Joined: Wed Sep 20, 2006 10:15 pm
Posts: 12
max wrote:
maybe because the DAO generation assumes you are putting your sessionfactory into a standard java locator api ? :)

Using a drivermanaged connection does not exclude usage of jndi for the sessionfactory. You can have hibernate do it automatically by specifying a name in the hibernate.cfg.xml on the session-factory element.


Hi there,

I have the exact same problem the OP mentioned. Unfortunately I posted that issue again since I missed this one in my search.

I specified a name in the cfg.xml for the session-factory element but it still throws the same error. At the moment I am only trying this out with one table. Is there any files or code snippets I can post to help diagnose this problem?

Thanks,
Dany.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.