0

我已经用 appfuse 创建了我的 J2EE 应用程序,我想将一些数据保存到数据库中,但是 hibernante 配置中的问题,这是一个例外:

警告 [http-8080-1] ConnectionProviderInitiator.initiateService(143) | HHH000181:没有遇到适当的连接提供程序,假设应用程序将提供连接 juin 07, 2013 5:16:05 PM org.apache.catalina.core.StandardWrapperValve 调用严重:Servlet.service() 用于 servlet 面引发异常 org.hibernate。 HibernateException:未设置“hibernate.dialect”时,连接不能为空

这是 pom.xml 中的数据库配置:

<dbunit.dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dbunit.dataTypeFactoryName>
<dbunit.operation.type>CLEAN_INSERT</dbunit.operation.type>
<hibernate.dialect>org.hibernate.dialect.MySQL5InnoDBDialect</hibernate.dialect>
<jdbc.groupId>mysql</jdbc.groupId>
<jdbc.artifactId>mysql-connector-java</jdbc.artifactId>
<jdbc.version>5.1.22</jdbc.version>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<!-- <jdbc.url>jdbc:mysql://localhost/${db.name}?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf-8&amp;amp;autoReconnect=true</jdbc.url> -->
<jdbc.url>jdbc:mysql://localhost/castor</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password></jdbc.password>         

如果我配置文件 hibernate.cfg.xml 服务器无法启动:

<hibernate-configuration>
    <session-factory>
     <mapping class="org.appfuse.model.Role"/>
         <mapping class="com.geviteam.castor.webapp.model.TrajetModel"/>
    </session-factory>
</hibernate-configuration>
4

2 回答 2

0

jdbc.properties 中有什么?它应该具有 pom.xml 中的属性并位于 target/classes 目录中(从 src/main/resources 复制它之后)。

于 2013-06-07T21:39:31.730 回答
0

您没有在 hibernate.cfg.xml 文件中提到数据库连接:

 <?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="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/databasename?autoReconnect=true</property>
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.pool_size">20</property>
        <property name="hibernate.connection.autocommit">false</property>
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">100</property>
        <property name="hibernate.c3p0.max_size">10</property>
        <property name="hibernate.c3p0.max_statements">10</property>
        <property name="hibernate.c3p0.min_size">10</property>
        <property name="hibernate.c3p0.timeout">100</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.hbm2ddl.auto">none</property>
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>
        <property name="hibernate.connection.release_mode">auto</property>

    <mapping resource="com/data/users.hbm.xml" />

</session-factory>

所需的罐子:mysql-connector-java-5.1.6-bin.jar, hibernate-commons-annotations-4.0.1.Final,hibernate-core-4.0.0.Final

于 2013-06-14T12:58:01.973 回答