Hibernate Version:2.1.4
Tomcat Version:4.1.30
I have configured my Tomcat DataSource JNDI with the follow code:
[code]
<Resource name="jdbc/quickhibernate" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/quickhibernate">
[/code]
I have write one jsp file to prove the Tomcat DataSource work fine.The Tomcat DataSource configration is ok!
So in hibernate.cfg.xml configuration file, i have setted the hibernate to use Tomcat DataSource.The setting code is listed :
[code]
<property name="connection.datasource">java:comp/env/jdbc/quickhibernate</property>
[/code]
Some other code please see the attached file,thanks!
I use the Cat example in the hibernate reference to see whether the hibernate work . I use "uuid.hex" generator to identify my cats.
It work well as hibernate reference show so.But i can't use "uuid.hex" as my real id identifier in my application.I want to use Customized Generator to generator my ID,so i implement the interface "net.sf.hibernate.id.TableGenerator" to be my own generator.
The related setting code in hbm.xml is list follow:
[code]
<generator class="com.michael.quickhibernate.beans.CBidGenerator">
<param name="table">GENERATORCB</param>
<param name="column">NEXT_HI_VALUE_COLUMN</param>
<param name="prefix">CAMX</param>
</generator>
[/code]
When i run my demo,the cat can not save into database.So i thought maybe it was something wrong on my customized Generator.I check my Generator class CBidGenerator and related table, they are not wrong.
I had to think that the problem may located at connection used by hibernate.
So i chang hibernate connection configuration to C3P0 DBCP. When i run my demo,the inconceivability event happened.The cat with customized generator work fine.
Why? Customized Generator can't run with JNDI DataSource connection?
Any reply will be appreciated! Thank very much for seeing this topic!
|