0

when i try to run my app in Tomcat 7.0

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

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

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 ?

Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

1

The exception tells you, you have to change your version attribute from 2.0 to 1.0.

hiimjames
  • 431
  • 4
  • 10
0

Java Persistence Api 2.0 (JPA 2) is a JAVA EE 6 feature.

Apache Tomcat 7 is not a JAVA EE 6 Application Server, is just a lightweight Servlet(3.0)/JSP(2.2) Container.

In order to use (any of the) JAVA EE features (CDI, JPA2, EJB3.1, JSF, etc...), you need a JAVA EE Application Server.

Sticking with Apache Tomcat, you could use Apache TomEE, that is (guess what?) a Tomcat JAVA EE compliant.

Otherwise use one of the other Application Servers out there (Glassfish, Jboss / Wildfly, etc...)

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • 1
    You can use JPA on Tomcat, also you can use JSF on Tomcat, it needs only one or two dependencies in Maven. I have one app on Tomcat using Spring, JPA, Primefaces. – hiimjames Dec 07 '14 at 17:38
  • I don't see them in its dependencies... You can tune up tomcat by adding libraries to make it almost Java ee compliant, but then why using tomcat at all? BTW last tomcat I've used extensively was 4, I'm not interested in its tuning, but thanks for adding info I've omitted – Andrea Ligios Dec 07 '14 at 21:34