如何在运行项目时解决Hibernate的错误?

时间:2018-05-01 21:24:12

标签: java hibernate java-ee hibernateexception

当我运行我的网络应用程序时,显示此错误,您可以帮我修复它吗? 我正在使用hibernate框架,我的项目运行成功,当我添加了一个宁静的Web服务并将其删除时,我的项目显示了这个错误。 我没有改变我的休眠配置中的任何东西。我只是从我的web.xml中删除一个Web服务servlet,注意它是一个maven项目

如果你愿意,我会告诉你更多信息。

Deploying on WildFly Application Server
    profile mode: false
    debug mode: false
    force redeploy: true
Undeploying ...
Initial deploying px-fs-web-stage to C:\Users\HP\Desktop\Stage 2018\jboss-eap-7.1\standalone\deployments\px-fs-web-stage-1.0-SNAPSHOT.war
Completed initial distribution of px-fs-web-stage
Deploying C:\Users\HP\Desktop\Stage 2018\jboss-eap-7.1\standalone\deployments\px-fs-web-stage-1.0-SNAPSHOT.war
"{\"WFLYCTL0080: Les services ont échoué\" => {\"jboss.persistenceunit.\\\"px-fs-web-stage-1.0-SNAPSHOT.war#ma.px.fs.stage_px-fs-web-stage_war_1.0-SNAPSHOTPU\\\"\" => \"org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set\"}}"
cd C:\Users\HP\Desktop\Stage 2018\sypex-stage\px-fs-web-stage; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_161" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dnetbeans.deploy=true -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 package\""
Scanning for projects...

我的hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/data/jpa  http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
       default-autowire="byName" default-lazy-init="true">

    <context:annotation-config />

    <beans profile="default" default-lazy-init="true">

        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:/SypexXADS" />
        </bean>

        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="packagesToScan">
                <list>
                    <value>ma.px.management.repository.service.bo</value>
                </list>
            </property>

            <property name="jtaDataSource" ref="dataSource" />
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
                </bean>
            </property>
            <property name="jpaPropertyMap">
                <map>
                    <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
                    <entry key="hibernate.transaction.factory_class" value="org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory" /> 
                    <entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                    <entry key="hibernate.hbm2ddl.auto" value="none" />
                    <entry key="hibernate.max_fetch_depth" value="1" />
                    <entry key="hibernate.connection.release_mode" value="auto" />
                    <entry key="hibernate.transaction.flush_before_completion" value="true" />
                    <entry key="hibernate.transaction.auto_close_session" value="true" />
                    <entry key="hibernate.enable_lazy_load_no_trans" value="true" />
                </map>
            </property>
        </bean>

        <jpa:repositories base-package="ma.px.management.repository.service.dao" entity-manager-factory-ref="entityManagerFactory" />

        <tx:jta-transaction-manager />
    </beans>

</beans>

谢谢。

1 个答案:

答案 0 :(得分:0)

您没有hibernate.dialect 使用数据库方言类作为值将其添加到jpaPropertyMap中

下面的MySQL示例

<property name="jpaPropertyMap">
     <map>
         <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
          ...other items
     </map>
</property>