hibernate配置proxool出错
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="proxool.pool_alias">proxoolPool</property>
<property name="proxool.xml">proxoolconf.xml</property>
<property name="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
</session-factory>
</hibernate-configuration>
proxool.xml
<?xml version='1.0' encoding='UTF-8'?>
<!--the proxool configuratin can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
<proxool>
<alias>proxoolPool</alias>
<driver-url>jdbc:microsoft:sqlserver://localhost:1433</driver-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<driver-properties>
<property name="username" value="sa"></property>
<property name="password" value="sa"/>
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<maximum-new-connections>20</maximum-new-connections>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>10</minimum-connection-count>
</proxool>
</something-else-entirely>
hibernate工程类
HibernateSessionFactory.java
package com.zsw.DB.Factory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
// 配置文件路径
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
// 单体session线程
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
// 工厂类
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* @返回 ThreadLocal Session 实例
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* @关闭单个ThreadLocal Session 实例
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
}
测试类Test.java
package com.zsw.DB.Factory;
public class Test {
public static void main(String[] args) {
HibernateSessionFactory.getSession();
System.out.println("=========");
}
}