hibernate、proxool配置
环境说明:tomcat6,hibernate3.6,proxool-0.9.1.jar,proxool-cglib.jar
hibernate.cfg.xml配置:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property> <property name="hibernate.proxool.xml">proxool.xml</property> <property name="hibernate.proxool.pool_alias">weicoop-proxool</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <!--<mapping resource="m/model/Student.hbm.xml" /> --> <mapping class="cn.mxc.weicoop.model.user.User"/> </session-factory> </hibernate-configuration>
proxool.xml配置:
<?xml version="1.0" encoding="UTF-8"?> <proxool> <alias>weicoop-proxool</alias> <driver-class>com.mysql.jdbc.Driver</driver-class> <driver-url>jdbc:mysql://localhost/weicoop?useUnicode=true&characterEncoding=utf-8</driver-url> <driver-properties> <property name="user" value="root" /> <property name="password" value="1234" /> </driver-properties> <maximum-connection-count>10</maximum-connection-count> <house-keeping-test-sql>selectCURRENT_DATE</house-keeping-test-sql> </proxool>
提示:
1、hibernate.cfg.xml和proxool.xml在同级目录下
2、要认真看好所有的属性配置,特别是属性名,很多问题都会因为错误的属性书写导致的
3、在hibernate3.6中不要还有自带的proxool-0.8.3.jar(用proxool-0.9.1.jar和proxool-cglib.jar代替)这会导致报错如下:
java.lang.reflect.InvocationTargetException 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.logicalcobwebs.proxool.ShutdownHook.remove(ShutdownHook.java:40) at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java:238) at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java:220) at org.logicalcobwebs.proxool.ShutdownHook.run(ShutdownHook.java:99) at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalStateException: Shutdown in progress at java.lang.Shutdown.remove(Shutdown.java:102) at java.lang.Runtime.removeShutdownHook(Runtime.java:218) ... 9 more