Hibernate4+proxool在执行session.beginTransaction()时报错

这个错貌似在Hibernate3是不会出现的,但我也不确定就是了;

proxool.xml主要代码如下,

<alias>dbpool</alias>
<driver-url>
jdbc:mysql://localhost:3306/hbmdb
</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
    <property name="user" value="root" />
    <property name="password" value="123456" />
</driver-properties>
<property name="hibernate.proxool.existing_pool">true</property>


HibernateUtil.java

public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();
    private static SessionFactory buildSessionFactory() {
        try {
            Configuration configuration = new Configuration().configure();
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            return configuration.buildSessionFactory(serviceRegistry);
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}

 

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

 在执行session.beginTransaction();时就会报错

 

2012-10-13 22:24:11 SqlExceptionHelper [WARN] SQL Error: 0, SQLState: 08001
2012-10-13 22:24:11 SqlExceptionHelper [ERROR] The url cannot be null
org.hibernate.exception.JDBCConnectionException: Could not open connection
2012-10-13 22:24:11 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet Event Manager threw exception
org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:200)
    at org.hibernate.tutorial.servlet.EventManagerServlet.doGet(EventManagerServlet.java:68)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)

1个回答

The url cannot be null 应该是hibernate4没识别



provider_class 在4中变化了 试试org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider

true //这个应该在hibernate配置文件 不在proxool.xml
hibernate4官方文档
[quote]
1.2.2. Proxool connection pool

Proxool is another open source JDBC connection pool distributed along with Hibernate in the lib/ directory. Hibernate uses its org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider for connection pooling if you set the hibernate.proxool.* properties. Unlike c3p0, proxool requires some additional configuration parameters, as described by the Proxool documentation available at http://proxool.sourceforge.net/configure.html.

Table 1.1. Important configuration properties for the Proxool connection pool

Property Description
hibernate.proxool.xml Configure Proxool provider using an XML file (.xml is appended automatically)
hibernate.proxool.properties Configure the Proxool provider using a properties file (.properties is appended automatically)
hibernate.proxool.existing_pool Whether to configure the Proxool provider from an existing pool
hibernate.proxool.pool_alias Proxool pool alias to use. Required.
[/quote]

somken
没刮胡子 我使用的hibernate 4.2 没有这个类 org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider
大约 7 年之前 回复
jinnianshilongnian
jinnianshilongnian 估计是忘了。。。 public class C3P0ConnectionProvider implements ConnectionProvider, Configurable, Stoppable { bug报告 还没有修复 https://hibernate.onjira.com/browse/HHH-7289 建议先用c3p0吧 或者自己改下源码 或者交给spring管理ds
大约 7 年之前 回复
cfyfm
cfyfm public class ProxoolConnectionProvider implements ConnectionProvider这里是不是还要实现Configurable接口,不敢确定他是忘了,还是本来就是这样设计的
大约 7 年之前 回复
cfyfm
cfyfm 我正在看源码,看得有点头疼
大约 7 年之前 回复
cfyfm
cfyfm org.hibernate.connection.ProxoolConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider; that provider will be used instead.说明hibernate会自动帮你替换成org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider
大约 7 年之前 回复
jinnianshilongnian
jinnianshilongnian 你看看最新版 还有这个问题吗? 去下载源码看下 是有这个bug
大约 7 年之前 回复
cfyfm
cfyfm org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider这个类忘了实现Configurable接口,导致无法加载Proxool的配置文件,无法Proxool使用连接池。这个是我网上找的,不知道是不是这个原因
大约 7 年之前 回复
jinnianshilongnian
jinnianshilongnian org.hibernate.connection.ProxoolConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider; that provider will be used instead. 你是按照我上边的配的吗?使用org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider 把hibernate配置文件 和详细的异常堆栈发上来
大约 7 年之前 回复
cfyfm
cfyfm 不行的,依然是报同样的错;org.hibernate.connection.ProxoolConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider; that provider will be used instead. 感觉像<driver-url>jdbc:mysql://localhost:3306/hbmdb</driver-url>错了,但我看不出它哪里错了;
大约 7 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!