Hibernate version:2.1
Mapping documents:<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration>
<session-factory name="java:hibernate/HibernateFactory">
<property name="connection.datasource">java:hibernate/HibernateFactory</property> <property name="show_sql">true</property>
<!-- Settings for a remote MySQL database. --> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">mysql://localhost/oozlooz</property> <property name="connection.username">oozlooz</property> <property name="connection.password">Jerich0</property> <!-- Use the C3P0 connection pool. --> <property name="c3p0.min_size">3</property> <property name="c3p0.max_size">5</property> <property name="c3p0.timeout">1800</property> <!-- Use EHCache but not the query cache. --> <property name="cache.provider_class">net.sf.ehcache.hibernate.Provider</property> <property name="cache.use_query_cache">false</property> <property name="cache.use_minimal_puts">false</property>
<mapping resource="oozlooz/dataobjects/persistence/user.hbm.xml"/> </session-factory> </hibernate-configuration>
Code between sessionFactory.openSession() and session.close(): //Hibernate session Session sess =HibernateUtil.currentSession(); Transaction tx=sess.beginTransaction(); try{ //Get the user class object referring to the table "user" user uObj = new user(); //Create the query Query query=sess.createQuery("INSERT INTO USER VALUES(:username,:joindate ,:imageURL, :password)"); query.setString("username",username); query.setDate("joindate",sqlNow); query.setString("imageURL",imageURL); query.setString("password",password); //Save this record sess.save(uObj); }catch(Exception e){ e.printStackTrace(); tx.rollback(); }finally{ tx.commit(); HibernateUtil.closeSession(); }
Full stack trace of any exception that occurs:net.sf.hibernate.HibernateException: Could not find datasource at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48) at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83) at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:65) at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155) at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789) at oozlooz.dataobjects.HibernateUtil.<clinit>(HibernateUtil.java:34) 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:274) at java.lang.Class.newInstance0(Class.java:306) at java.lang.Class.newInstance(Class.java:259) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:977) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3991) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4335) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardHost.start(StandardHost.java:789) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478) at org.apache.catalina.core.StandardService.start(StandardService.java:476) at org.apache.catalina.core.StandardServer.start(StandardServer.java:2298) at org.apache.catalina.startup.Catalina.start(Catalina.java:556) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422) Caused by: javax.naming.NameNotFoundException: Name hibernate is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingContext.java:768) at org.apache.naming.NamingContext.lookup(NamingContext.java:151) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136) at javax.naming.InitialContext.lookup(InitialContext.java:347) at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44) ... 28 more
Name and version of the database you are using:mysql 4
Debug level Hibernate log excerpt:
I am using exactly the same code given in the Hibernate tutorials with Tomcat5, only difference is that I dont want to use DBCP connection pool but C3PO connection pool, I cant find relevent documents anywhere. Please help !
|