【问题标题】:hibernate configuration error休眠配置错误
【发布时间】:2013-06-07 16:06:31
【问题描述】:

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

警告 [http-8080-1] ConnectionProviderInitiator.initiateService(143) | HHH000181:没有遇到合适的连接提供程序,假设应用程序将提供连接 2013 年 6 月 7 日下午 5:16:05 org.apache.catalina.core.StandardWrapperValve 调用 严重:Servlet 面的 Servlet.service() 引发异常 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>

【问题讨论】:

  • 检查我发布的答案。

标签: hibernate jakarta-ee appfuse


【解决方案1】:

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

【讨论】:

  • 在我的 jdbc.properties 中: jdbc.driverClassName=${jdbc.driverClassName} jdbc.url=${jdbc.url} jdbc.username=${jdbc.username} jdbc.password=${ jdbc.password} hibernate.dialect=${hibernate.dialect} # 在 pom.xml 中定义的 Hibernate3 Maven 插件需要 hibernate.connection.username=${jdbc.username} hibernate.connection.password=${jdbc.password} hibernate .connection.url=${jdbc.url} hibernate.connection.driver_class=${jdbc.driverClassName}
  • 我认为当我添加休眠连接的属性服务器停止工作时由 hibernate.cfg.xml 引起的问题
  • 如果运行“mvn resources:resources”,target/classes 中的 hibernate.properties 中的值是否正确?
  • 在 hibernate.properties 中我找到了休眠搜索的默认配置:app.search.index.basedir=${user.home}/castor-0.0.1/index # hibernate.search.default。 directory_provider=文件系统 hibernate.search.default.locking_strategy=simple hibernate.search.default.exclusive_index_use=true hibernate.search.lucene_version=LUCENE_35 hibernate.search.analyzer=org.apache.lucene.analysis.en.EnglishAnalyzer hibernate.search.worker .batch_size=100
  • 删除 hibernate.connection.username 和 hibernate.connection.password 可能会有所帮助。
【解决方案2】:

你没有在 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.jarhibernate-commons-annotations-4.0.1.Finalhibernate-core-4.0.0.Final

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2015-07-19
    • 2011-04-30
    • 2010-11-08
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多