-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Tools Eclipse and JNDI configuration
PostPosted: Mon Jul 31, 2006 8:48 am 
Newbie

Joined: Mon Jul 31, 2006 8:36 am
Posts: 4
I have used hibernate tools 2 months ago without any problem.
But I have downloaded the last Jboss Eclipse IDE which is packaged with Hibernate Tools. I have done some hibernate reverse engeneering on a mySQL database. (code is well generated) It automaticcaly generates dao code with a jndi configuration.

But I don't know how to use JNDI. Could you explain a little or give an example.

Thanks a lot

Francois

public class RelationDaoHome {

private static final Log log = LogFactory.getLog(RelationHome.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 version:3.1

Mapping documents:
<?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="SessionFactory">
<property name="hibernate.session_factory_name">java:hibernate/SessionFactory</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">hotjdb</property>
<property name="hibernate.connection.url">jdbc:mysql://mars.pc.local:3306/chebi</property>
<property name="hibernate.connection.username">flefevre</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Structures.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/ChemicalData.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Relation.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Names.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Reference.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/DefaultStructures.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Comments.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/DatabaseAccession.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Compounds.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/AutogenStructures.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Vertice.hbm.xml" />
<mapping resource="fr/cns/genoscope/nemo/chebi/domain/Ontology.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
31 juil. 2006 14:28:17 fr.cns.genoscope.nemo.chebi.domain.CompoundsHome getSessionFactory
GRAVE: Could not locate SessionFactory in JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at fr.cns.genoscope.nemo.chebi.domain.CompoundsHome.getSessionFactory(CompoundsHome.java:27)
at fr.cns.genoscope.nemo.chebi.domain.CompoundsHome.<init>(CompoundsHome.java:22)
at fr.cns.genoscope.nemo.chebi.tests.TestAccess.main(TestAccess.java:15)
Exception in thread "main" java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at fr.cns.genoscope.nemo.chebi.domain.CompoundsHome.getSessionFactory(CompoundsHome.java:30)
at fr.cns.genoscope.nemo.chebi.domain.CompoundsHome.<init>(CompoundsHome.java:22)
at fr.cns.genoscope.nemo.chebi.tests.TestAccess.main(TestAccess.java:15)
Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.