gpt4 book ai didi

java - 错误 persistence.xml jpa 2 spring hibernate 3

转载 作者:行者123 更新时间:2023-12-01 12:09:30 25 4
gpt4 key购买 nike

当我尝试在 Tomcat 7.0 中运行我的应用程序时

我使用 hibernate 3 + spring + mysql 作为数据库

我收到此异常:

Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 19; cvc-complex-type.3.1: Value '2.0' of attribute 'version' of element 'persistence' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '1.0'.

applicationcontext.xml

<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocation" value="classpath*:META-INF/classes/persistence_hibernate.xml"/>

<property name="defaultDataSource" ref="dataSource"></property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
</bean>

<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
<context:annotation-config></context:annotation-config>

persistence_hibernate.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="UP_AB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>

<property name="hibernate.hbm2ddl.auto" value="update" />


<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

<property name="hibernate.show_sql" value="true" />


</properties>
</persistence-unit>

这是我使用的依赖项

    <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>

tomcat有问题,我应该使用Jboss还是类似的东西?

最佳答案

异常告诉您,您必须将版本属性从 2.0 更改为 1.0。

关于java - 错误 persistence.xml jpa 2 spring hibernate 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27343416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com