Hi,
I'm a completely newbie to Hibernate.
I cannot obtain the SessionFactory with the following configuration and code. Could someone help me to understand what is going wrong?
Thank you very much,
Phong NGUYEN.
Hibernate version: Hibernate 2.1.3
Mapping documents: <hibernate-configuration>
<session-factory> <!-- properties --> <property name="connection.datasource">java:comp/env/jdbc/testDB</property> <property name="connection.username">mangosteen</property> <property name="connection.password"></property> <property name="show_sql">true</property> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!-- configuration pool via c3p0--> <property name="c3p0.acquire_increment">1</property> <property name="c3p0.idle_test_period">100</property> <!-- seconds --> <property name="c3p0.max_size">100</property> <property name="c3p0.max_statements">0</property> <property name="c3p0.min_size">10</property> <property name="c3p0.timeout">100</property> <!-- seconds -->
<!-- mapping files --> <mapping resource="/Application.hbm.xml"/> <mapping resource="/Address.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close(): Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction();
Where public class HibernateUtil { private static Log log = LogFactory.getLog(HibernateUtil.class);
private static final SessionFactory sessionFactory; static { try { // Create the SessionFactory sessionFactory = new Configuration().configure() .buildSessionFactory(); } catch (Throwable ex) { log.error("Initial SessionFactory creation failed.", ex); throw new ExceptionInInitializerError(ex); } }
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException { Session s = (Session) session.get(); // Open a new Session, if this Thread has none yet if (s == null) { s = sessionFactory.openSession(); session.set(s); } return s; }
public static void closeSession() throws HibernateException { Session s = (Session) session.get(); session.set(null); if (s != null) s.close(); } }
Full stack trace of any exception that occurs:
java.lang.UnsupportedOperationException
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:116)
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:554)
net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:56)
net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3297)
net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3277)
net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2220)
com.siliconmemory.struts.ApplicationAction.createApp(ApplicationAction.java:70)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Name and version of the database you are using: MySQL 4.0.21-nt
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: [INFO] Environment - Hibernate 2.1.3 [INFO] Environment - loaded properties from resource hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true} [INFO] Environment - using CGLIB reflection optimizer [INFO] Configuration - configuring from resource: /hibernate.cfg.xml [INFO] Configuration - Configuration resource: /hibernate.cfg.xml [INFO] Configuration - Mapping resource: /com/siliconmemory/Application.hbm.xml [INFO] Binder - Mapping class: com.siliconmemory.Application -> application [INFO] Configuration - Mapping resource: /com/siliconmemory/Address.hbm.xml [INFO] Binder - Mapping class: com.siliconmemory.Address -> address [INFO] Configuration - Configured SessionFactory: null [INFO] Configuration - processing one-to-many association mappings [INFO] Configuration - processing one-to-one association property references [INFO] Configuration - processing foreign key constraints [INFO] Dialect - Using dialect: net.sf.hibernate.dialect.MySQLDialect [INFO] SettingsFactory - Use outer join fetching: false [INFO] NamingHelper - JNDI InitialContext properties:{} [INFO] DatasourceConnectionProvider - Using datasource: java:comp/env/jdbc/testDB [INFO] TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended) [INFO] SettingsFactory - Use scrollable result sets: false [INFO] SettingsFactory - Use JDBC3 getGeneratedKeys(): false [INFO] SettingsFactory - Optimize cache for minimal puts: false [INFO] SettingsFactory - echoing all SQL to stdout [INFO] SettingsFactory - Query language substitutions: {} [INFO] SettingsFactory - cache provider: net.sf.ehcache.hibernate.Provider [INFO] Configuration - instantiating and configuring caches [INFO] SessionFactoryImpl - building session factory [INFO] SessionFactoryObjectFactory - no JNDI name configured [WARN] RequestProcessor - Unhandled Exception thrown: class java.lang.UnsupportedOperationException
java:comp/env/jdbc/testDB is configured with Tomcat
<Resource auth="Container" description="Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file." name="jdbc/testDB" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/testDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10</value>
</parameter>
<!-- Class name for the official MySQL Connector/J driver -->
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>
</parameter>
<parameter>
<name>username</name>
<value>mangosteen@localhost</value>
</parameter>
</ResourceParams>
|