0

我刚开始使用 Hibernate,我一直在尝试将它与 H2 连接起来。

我的 hibernate.cfg.xml 文件如下所示:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">org.h2.Driver</property>
        <property name="connection.driver_class">jdbc:h2:mem:test</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"/>
        <!-- DB schema will be updated if needed -->
        <!-- <property name="hbm2ddl.auto">update</property> -->

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>
    </session-factory>
</hibernate-configuration>

我收到一条错误消息:Cannot resolve class 'jdbc'. 我用 Maven 安装了 H2。

4

1 回答 1

2

我相信你可能想使用'。而不是你的班级名称中的':'。

http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/session-configuration.html

或者看起来您已经交换了驱动程序类和连接 url 属性。

于 2013-05-08T19:19:41.350 回答