I followed this hibernate tutorial at
http://www.gloegl.de/8.html and I a little modification to it so that it runs in J2EE app. I could get it to work with regular jdbc connection based on the setting below:-
Code:
<session-factory>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://myserverbox:1433;databaseName=hibernateDb</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">user</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="test/hbm/dao/beans/Event.hbm.xml" />
</session-factory>
So, I tried to convert it to run with connection pooling with the following settings:-
Code:
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/hibernateDb</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="test/hbm/dao/beans/Event.hbm.xml" />
</session-factory>
When I run it again, I get the following error:-
Code:
1/12/06 11:37:23:225 CST] 0000003a SystemOut O Hibernate: insert into Event (eventtitle) values (?)
[1/12/06 11:37:23:245 CST] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 0, SQLState: HY000
[1/12/06 11:37:23:255 CST] 0000003a JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions [IBM][SQLServer JDBC Driver]Unsupported method: Connection.prepareStatement
[1/12/06 11:37:23:295 CST] 0000003a ServletWrappe A SRVE0242I: [hbmEAR] [/hbm] [/WEB-INF/jsp/test.jsp]: Initialization successful.
[1/12/06 11:37:23:305 CST] 0000003a LocalTranCoor W WLTC0033W: Resource jdbc/hibernateDb rolled back in cleanup of LocalTransactionContainment.
[1/12/06 11:37:23:315 CST] 0000003a LocalTranCoor W WLTC0032W: One or more local transaction resources were rolled back during the cleanup of a LocalTransactionContainment.
[1/12/06 11:37:23:285 CST] 0000003a SystemErr R org.hibernate.exception.GenericJDBCException: could not insert: [test.hbm.dao.beans.Event] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
At first, I thought I messed up my JNDI settings in my server and web.xml. So, I did a test on the following codes with the same sql statement generated by hibernate, and it works:-
Code:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/hibernateDb");
Connection con = ds.getConnection();
PreparedStatement ps = con.prepareStatement("insert into Event(eventtitle) values(?)");
ps.setString(1, "TEST");
ps.executeUpdate();
con.close();
May I know where I set wrongly in my hibernate.cfg.xml for my connection pooling? I have been messing around for 2 hours now, but still couldn't get it to work.
Any tips would be greatly appreciated! Thanks.
Code: