Hibernate error: Not binding factory to JNDI, no JNDI name configured
Hello everyone,
I'm in a bit of a quandry.
I'm new to Java, and even newer to Hibernate, and am trying to do a bit of basic Java programming using Hibernate to get me started.
Unfortunately, it's not going so well with an error cropping up that I can't sort out.
The error, and the code I'm using, is as follows:
Error:
25-Oct-2010 16:28:37 org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
25-Oct-2010 16:28:37 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.6.0.Final
25-Oct-2010 16:28:37 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
25-Oct-2010 16:28:37 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
25-Oct-2010 16:28:37 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
25-Oct-2010 16:28:38 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
25-Oct-2010 16:28:38 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
25-Oct-2010 16:28:38 org.hibernate.util.DTDEntityResolver resolveEntity
WARNING: recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
25-Oct-2010 16:28:38 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : contact.hbm.xml
25-Oct-2010 16:28:38 org.hibernate.util.DTDEntityResolver resolveEntity
WARNING: recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
25-Oct-2010 16:28:38 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
25-Oct-2010 16:28:38 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: mqp.Test_Hib -> TEST_HIB
25-Oct-2010 16:28:38 org.hibernate.cfg.Configuration applyHibernateValidatorLegacyConstraintsOnDDL
INFO: Hibernate Validator not found: ignoring
25-Oct-2010 16:28:38 org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
25-Oct-2010 16:28:38 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
25-Oct-2010 16:28:38 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
25-Oct-2010 16:28:38 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
25-Oct-2010 16:28:38 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@stringtakenoutbyme
25-Oct-2010 16:28:38 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=usertakenoutbyme, password=****}
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Database ->
name : Oracle
version : Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning and Data Mining options
major : 10
minor : 2
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Driver ->
name : Oracle JDBC driver
version : 10.2.0.1.0
major : 10
minor : 2
25-Oct-2010 16:28:38 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
25-Oct-2010 16:28:38 org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
25-Oct-2010 16:28:38 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
25-Oct-2010 16:28:38 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
25-Oct-2010 16:28:38 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
25-Oct-2010 16:28:38 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
25-Oct-2010 16:28:38 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
25-Oct-2010 16:28:38 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Inserting Record
Done
Hibernate: insert into TEST_HIB (NAME, EMAIL, ID) values (?, ?, ?)
(The record doesn't get inserted)
FirstExample.java:
package mqp;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Test_Hib contact = new Test_Hib();
contact.setId(3);
contact.setName("test_1");
contact.setEmail("test_1yahoo.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}
contact.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="mqp.Test_Hib" table="TEST_HIB">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>
<property name="name">
<column name="NAME" />
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
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>
<property name="connection.url">
jdbc:oracle:thin:@stringtakenoutbyme
</property>
<property name="connection.username">
usernametakenoutbyme
</property>
<property name="connection.password">
passwordtakenoutbyme
</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="current_session_context_class">
thread
</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">
true
</property>
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Test_Hib.class:
package mqp;
/**
* @author Deepak Kumar
*
* Java Class to map to the datbase Contact Table
*/
public class Test_Hib {
private String name;
private String email;
private long id;
/**
* @return Email
*/
public String getEmail() {
return email;
}
/**
* @return First Name
*/
public String getName() {
return name;
}
/**
* @param string Sets the Email
*/
public void setEmail(String string) {
email = string;
}
/**
* @param string Sets the First Name
*/
public void setName(String string) {
name = string;
}
/**
* @return ID Returns ID
*/
public long getId() {
return id;
}
/**
* @param l Sets the ID
*/
public void setId(long l) {
id = l;
}
}
I've tried lots of solutions that were available online, but couldn't get any of them to work for me...this may well be because of my lack of Java/Hibernate knowledge, and not being able to apply them to my situation.
Any help will be hugely appreciated!
Robin :-)