I know it is a very easy question but I don't know what to do and I don't find a answer outside in the net.
I use HibernateTools 3.2 beta8 and eclipse 3.2.
I used the reverse engineering function from hibernate and generated me fhe DAO, Domain Code and Mapping files.
Now I wanted to get some data out of the Table or insert some but everything I try fail.
I won't paste the files generated from Hibernate, because I think you know how they look like.
I also generated a HibernateUtil file, because I read about this but I also get an error. So if you can help me or know a good tutorial, I would be happy.
HibernateUtil
Code:
package de.fhg.scai.bio.csr.io.database.communication;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Error
Code:
2007-04-20 17:07:57,763 INFO [de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:116)] >> Starting workflow: Connect with database
2007-04-20 17:07:57,763 INFO [de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:64)] >> (13/13) - Communicating with database ...
2007-04-20 17:07:57,856 INFO [org.hibernate.cfg.Environment.<clinit>(Environment.java:509)] Hibernate 3.2.3
2007-04-20 17:07:57,871 INFO [org.hibernate.cfg.Environment.<clinit>(Environment.java:542)] hibernate.properties not found
2007-04-20 17:07:57,873 INFO [org.hibernate.cfg.Environment.buildBytecodeProvider(Environment.java:676)] Bytecode provider name : cglib
2007-04-20 17:07:57,895 INFO [org.hibernate.cfg.Environment.<clinit>(Environment.java:593)] using JDK 1.4 java.sql.Timestamp handling
2007-04-20 17:07:58,122 INFO [org.hibernate.cfg.Configuration.configure(Configuration.java:1426)] configuring from resource: /hibernate.cfg.xml
2007-04-20 17:07:58,123 INFO [org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1403)] Configuration resource: /hibernate.cfg.xml
2007-04-20 17:07:58,353 INFO [org.hibernate.cfg.Configuration.addResource(Configuration.java:553)] Reading mappings from resource : de/fhg/scai/bio/csr/io/database/hibernate/Test.hbm.xml
2007-04-20 17:07:58,565 INFO [org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:300)] Mapping class: de.fhg.scai.bio.csr.io.database.hibernate.Test -> TEST
2007-04-20 17:07:58,584 INFO [org.hibernate.cfg.Configuration.addResource(Configuration.java:553)] Reading mappings from resource : de/fhg/scai/bio/csr/io/database/hibernate/Secondtest.hbm.xml
2007-04-20 17:07:58,662 INFO [org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:300)] Mapping class: de.fhg.scai.bio.csr.io.database.hibernate.Secondtest -> SECONDTEST
2007-04-20 17:07:58,664 INFO [org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1541)] Configured SessionFactory: null
2007-04-20 17:07:58,849 INFO [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:41)] Using Hibernate built-in connection pool (not for production use!)
2007-04-20 17:07:58,851 INFO [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:42)] Hibernate connection pool size: 20
2007-04-20 17:07:58,858 INFO [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:45)] autocommit mode: false
2007-04-20 17:07:58,886 INFO [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:80)] using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@bio-ora:1521:chemdb01
2007-04-20 17:07:58,887 INFO [org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:86)] connection properties: {user=csr, password=****}
2007-04-20 17:07:59,367 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
2007-04-20 17:07:59,368 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)] JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
2007-04-20 17:07:59,397 INFO [org.hibernate.dialect.Dialect.<init>(Dialect.java:152)] Using dialect: org.hibernate.dialect.Oracle9Dialect
2007-04-20 17:07:59,405 INFO [org.hibernate.transaction.TransactionFactoryFactory.buildTransactionFactory(TransactionFactoryFactory.java:31)] Using default transaction strategy (direct JDBC transactions)
2007-04-20 17:07:59,408 INFO [org.hibernate.transaction.TransactionManagerLookupFactory.getTransactionManagerLookup(TransactionManagerLookupFactory.java:33)] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2007-04-20 17:07:59,409 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:143)] Automatic flush during beforeCompletion(): disabled
2007-04-20 17:07:59,409 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:147)] Automatic session close at end of transaction: disabled
2007-04-20 17:07:59,410 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:154)] JDBC batch size: 15
2007-04-20 17:07:59,410 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:157)] JDBC batch updates for versioned data: disabled
2007-04-20 17:07:59,411 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:162)] Scrollable result sets: enabled
2007-04-20 17:07:59,412 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:170)] JDBC3 getGeneratedKeys(): disabled
2007-04-20 17:07:59,415 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:178)] Connection release mode: auto
2007-04-20 17:07:59,416 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:196)] Default schema: CSR
2007-04-20 17:07:59,416 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:205)] Default batch fetch size: 1
2007-04-20 17:07:59,417 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:209)] Generate SQL with comments: disabled
2007-04-20 17:07:59,418 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:213)] Order SQL updates by primary key: disabled
2007-04-20 17:07:59,419 INFO [org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:382)] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2007-04-20 17:07:59,429 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory.<init>(ASTQueryTranslatorFactory.java:24)] Using ASTQueryTranslatorFactory
2007-04-20 17:07:59,430 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:221)] Query language substitutions: {}
2007-04-20 17:07:59,430 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:226)] JPA-QL strict compliance: disabled
2007-04-20 17:07:59,431 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:231)] Second-level cache: enabled
2007-04-20 17:07:59,431 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:235)] Query cache: disabled
2007-04-20 17:07:59,431 INFO [org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:369)] Cache provider: org.hibernate.cache.NoCacheProvider
2007-04-20 17:07:59,432 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:250)] Optimize cache for minimal puts: disabled
2007-04-20 17:07:59,432 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:259)] Structured second-level cache entries: disabled
2007-04-20 17:07:59,444 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:286)] Statistics: disabled
2007-04-20 17:07:59,445 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:290)] Deleted entity synthetic identifier rollback: disabled
2007-04-20 17:07:59,445 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:305)] Default entity-mode: pojo
2007-04-20 17:07:59,446 INFO [org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:309)] Named query checking : enabled
2007-04-20 17:07:59,526 INFO [org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:161)] building session factory
2007-04-20 17:08:00,125 INFO [org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:82)] Not binding factory to JNDI, no JNDI name configured
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 de.fhg.scai.bio.csr.io.database.hibernate.TestHome.getSessionFactory(TestHome.java:27)
at de.fhg.scai.bio.csr.io.database.hibernate.TestHome.<init>(TestHome.java:22)
at de.fhg.scai.bio.csr.io.database.communication.HibernateTest.run(HibernateTest.java:55)
at de.fhg.scai.bio.csr.workflows.algorithms.DatabaseCommunication.run(DatabaseCommunication.java:73)
at de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:93)
at de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:117)
2007-04-20 17:08:00,164 ERROR [de.fhg.scai.bio.csr.io.database.hibernate.TestHome.getSessionFactory(TestHome.java:30)] 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 de.fhg.scai.bio.csr.io.database.hibernate.TestHome.getSessionFactory(TestHome.java:27)
at de.fhg.scai.bio.csr.io.database.hibernate.TestHome.<init>(TestHome.java:22)
at de.fhg.scai.bio.csr.io.database.communication.HibernateTest.run(HibernateTest.java:55)
at de.fhg.scai.bio.csr.workflows.algorithms.DatabaseCommunication.run(DatabaseCommunication.java:73)
at de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:93)
at de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:117)
2007-04-20 17:08:00,168 ERROR [de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:105)] java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
2007-04-20 17:08:00,169 INFO [de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:118)] >> Exiting workflow ERROR
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
at de.fhg.scai.bio.csr.io.database.hibernate.TestHome.getSessionFactory(TestHome.java:31)
at de.fhg.scai.bio.csr.io.database.hibernate.TestHome.<init>(TestHome.java:22)
at de.fhg.scai.bio.csr.io.database.communication.HibernateTest.run(HibernateTest.java:55)
at de.fhg.scai.bio.csr.workflows.algorithms.DatabaseCommunication.run(DatabaseCommunication.java:73)
at de.fhg.scai.bio.csr.workflows.modules.ProtocolDatabaseWorkflow.execute(ProtocolDatabaseWorkflow.java:93)
at de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:117)
2007-04-20 17:08:00,191 INFO [de.fhg.scai.bio.csr.workflows.Workflow$ExecuteModulesThread.run(Workflow.java:133)] logger Statistics debug: 0 info: 112 warn: 9 error: 6 fatal: 0