Hibernate 4.0.1到4.3.5:无法建立JDBC连接

时间:2016-01-08 18:34:48

标签: java hibernate jdbc derby

我有一个使用Hibernate 4.0.1与derby数据库交互的项目。这很好。这是一个简单连接到数据库但不做任何事情的示例程序:

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DbTestMain {
    public static void main(String... args){
        Configuration derbyConfiguration = new Configuration().configure("hibernate-derby.cfg.xml");

        SessionFactory derbySF = derbyConfiguration.buildSessionFactory();
        Session derbySession = derbySF.openSession();

        derbySession.close();
    }
}

这是相应的配置:

<?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>

        <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>

        <property name="connection.url">jdbc:derby:TestDerbyDB;create=true</property>
        <property name="connection.username"></property>
        <property name="connection.password"></property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.DerbyDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <property name="hbm2ddl.auto">update</property>
    </session-factory>
</hibernate-configuration>

这是我的课程路径:

工作正常。但是当我尝试更新到Hibernate 4.3.5时,我收到了这个错误:

Exception in thread "main" org.hibernate.HibernateException: Unable to make JDBC Connection [jdbc:derby:C:\Users\Kevin\Desktop\TestDerbyDB;create=true]
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:77)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at DbTestMain.main(DbTestMain.java:9)

我唯一做的就是改变我的类路径以使用Hibernate 4.3.5:

(出于某种原因,Hibernate 4.0.1需要commons-collections,但Hibernate 4.3.5不需要。)

我没有改变任何其他内容,错误消息令人沮丧地含糊不清。有什么我做错了吗?我需要在代码中更新某些内容吗?

我的实际情况是我正在尝试从旧的(Hibernate 4.0.1)项目中提取代码并将其放入更新的(Hibernate 4.3.5)项目中。

0 个答案:

没有答案