简体   繁体   English

错误persistence.xml jpa 2春季休眠3

[英]error persistence.xml jpa 2 spring hibernate 3

when i try to run my app in Tomcat 7.0 当我尝试在Tomcat 7.0中运行我的应用程序时

i use hibernate 3 + spring + mysql for DB 我使用Hibernate 3 + Spring + MySQL for DB

i receive this exception : 我收到此异常:

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 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_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>

and this is the dependencies i use 这是我使用的依赖

    <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>

there is a problem with tomcat, should I use Jboss or something like that ? tomcat有问题,我应该使用Jboss或类似的东西吗?

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

Java Persistence Api 2.0 (JPA 2) is a JAVA EE 6 feature. Java Persistence Api 2.0(JPA 2)是JAVA EE 6的功能。

Apache Tomcat 7 is not a JAVA EE 6 Application Server, is just a lightweight Servlet(3.0)/JSP(2.2) Container. Apache Tomcat 7不是JAVA EE 6应用服务器,它只是一个轻量级的Servlet(3.0)/ JSP(2.2)容器。

In order to use (any of the) JAVA EE features (CDI, JPA2, EJB3.1, JSF, etc...), you need a JAVA EE Application Server. 为了使用(任何) JAVA EE功能 (CDI,JPA2,EJB3.1,JSF等),您需要一个JAVA EE应用服务器。

Sticking with Apache Tomcat, you could use Apache TomEE , that is (guess what?) a Tom cat JAVA EE compliant . 坚持使用Apache Tomcat,您可以使用Apache TomEE ,即(猜猜是什么?) Tom cat JAVA EE兼容

Otherwise use one of the other Application Servers out there (Glassfish, Jboss / Wildfly, etc...) 否则,请使用其中的其他应用程序服务器之一(Glassfish,Jboss / Wildfly等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM