我的程序运行良好,直到我开始使用持久性并使用EntityManager
@Inject
.
抛出了很多错误,但我认为这是最阻塞的一个。
它说明了一个意想不到的元素,但我在网上找不到任何有用的信息。
日志:
Connected to server
[2017-05-16 09:13:17,808] Artifact web-example:war exploded: Artifact is being deployed, please wait...
mei 16, 2017 9:13:18 PM org.apache.tomee.catalina.TomcatWebAppBuilder deployWebApps
INFO: using default host: localhost
mei 16, 2017 9:13:18 PM org.apache.tomee.catalina.TomcatWebAppBuilder init
INFO: ------------------------- localhost -> /
mei 16, 2017 9:13:18 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
WARNING: jar '/Users/renzo/development/school/dea/spotitube/app/target/web-example-1.0-SNAPSHOT/WEB-INF/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar' contains offending class: javax.persistence.Entity. It will be ignored.
mei 16, 2017 9:13:18 PM org.apache.tomee.catalina.TomEEClassLoaderEnricher validateJarFile
WARNING: jar '/Users/renzo/development/school/dea/spotitube/app/target/web-example-1.0-SNAPSHOT/WEB-INF/lib/jboss-transaction-api_1.1_spec-1.0.1.Final.jar' contains offending class: javax.transaction.Transaction. It will be ignored.
mei 16, 2017 9:13:18 PM org.apache.openejb.config.ConfigurationFactory configureApplication
INFO: Configuring enterprise application: /Users/renzo/development/school/dea/spotitube/app/target/web-example-1.0-SNAPSHOT
mei 16, 2017 9:13:18 PM org.apache.openejb.config.ReadDescriptors deploy
SEVERE: Unable to load Persistence Unit from EAR: /Users/renzo/development/school/dea/spotitube/app/target/web-example-1.0-SNAPSHOT, module: file:/Users/renzo/development/school/dea/spotitube/app/target/web-example-1.0-SNAPSHOT/WEB-INF/classes/. Exception: unexpected element (uri:"http://xmlns.jcp.org/xml/ns/persistence", local:"persistence"). Expected elements are <{http://java.sun.com/xml/ns/persistence}persistence>
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://xmlns.jcp.org/xml/ns/persistence", local:"persistence"). Expected elements are <{http://java.sun.com/xml/ns/persistence}persistence>
/resources/META-INF/persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
http://xmlns.jcp.org/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit
name="mysql"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>
nl.han.dea.domain.User
</class>
<properties>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/Spotitube?autoReconnect=true&useSSL=false&serverTimezone=UTC"/>
<property name="hibernate.connection.username" value="spotitube"/>
<property name="hibernate.connection.password" value="java"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.han.dea</groupId>
<artifactId>web-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>web-example</name>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.6.Final</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>