JPA2.0遇到的问题:NoSuchMethodError... getValidationMode()Ljavax/persistence/ValidationMode;

整合JPA2.0的时候遇到这样的错误:

Invocation of init method failed; nested exce
ption is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.
getValidationMode()Ljavax/persistence/ValidationMode;

原因是getValidationMode()是JavaEE6中才有的,查看下官方文档:

http://docs.oracle.com/javaee/6/api/javax/persistence/spi/PersistenceUnitInfo.html#getValidationMode()

getValidationMode

ValidationMode getValidationMode()

Returns the validation mode to be used by the persistence provider for the persistence unit. The validation mode corresponds to the validation-mode element in the persistence.xml file.

Returns:

the validation mode to be used by the persistence provider for the persistence unit

Since:

Java Persistence 2.0

Tomcat是一个Servlet容器,实现了Servlet规范,并没有实现EJB、JMS、JPA规范,并不是一个完整的Java EE实现。

对于Tomcat,只需要在项目中添加jpa2.0的实现就可以了。

resin可以支持sun的j2ee,实现了如下的规范:

20140513-Java01

为了使用JPA2.0,需要使用实现了JPA2.0规范的resin版本:

http://blog.caucho.com/2010/10/27/are-we-there-yet-resin-4-java-ee-6-web-profile-certification/

arthinking wechat
欢迎关注itzhai公众号