cfyfm
2012-10-13 23:02 阅读 322
已采纳

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条回答 默认 最新

  • 已采纳
    jinnianshilongnian jinnianshilongnian 2012-10-14 09:15

    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]

    点赞 评论 复制链接分享

相关推荐