问题
I am using javax.persistence.JoinColumn.foreignKey
in my code. The project is working fine using WildFly server, but when I use Jboss EAP 6.1, it gives below error:
java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2884) org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:3051) org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1839) org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:963) org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:796)
When I further investigated the issue, I found that JBoss Library does not support Join columns.
However, my project library supports Join column and I intent to use these library in my code. But Jboos libraries seem to be overriding the libraries in the class path.
I tried below code in jboss-deployment-structure.xml
<exclusions>
<module name="javax.persistence.api"/>
<module name="javaee.api"/>
</exclusions>
But I am getting below error
11:19:55,195 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."myappl.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."myappl.war".PARSE: JBAS018733: Failed to process phase PARSE of deployment "myappl.war" Caused by: java.lang.IllegalStateException: JBWS021001: Unexpected element parsing handlers: handler-config
回答1:
The root cause of this problem is that EAP 6.3.x is based on the Java EE 6 specification and JPA 2.0 is part of this specification. The most recent versions of Hibernate (4.3.x) bring with version 2.1 of JPA, which is part of the Java EE 7 specification. Theoretically, to solve the problem, it was enough to exclude 'org.hibernate' modules and 'javax.persistence' in jboss-deployment-structure.xml file, but it does not solve the problem. According to Red Hat, this is a BUG.
1) A solution is to use the version of Hibernate present in the distribution of EAP 6.3.x. Resolve, but an application can not be held to versions of a server libraries.
2) Another solution is to change the version of JPA 2.0 to 2.1 directly in the distribution, located in \JBOSS_DIST\modules\system\layers\base\javax\persistence\api\main. Also resolves, but this solution is not acceptable, since the applications using the Hibernate version 6.3.x present in the EAP may be affected.
3) We could would be to follow the steps in this address http://mariemjabloun.blogspot.com.br/2014/03/use-jboss-jpa-21-and-hibernate-43-on.html, but particularly found a solution very laborious.
4) Finally, after numerous searches and attempts, found a reasonable solution to work around the problem, at the very site of RedHat: https://access.redhat.com/solutions/404223. I believe in future versions of EAP, it should be corrected.
回答2:
JBoss EAP 6.x is compliant with JPA 2.0 API while javax.persistence.ForeignKey has been added in JPA 2.1.
In order to make it work you need to integrate it manually. A possible workaround can be found here
来源:https://stackoverflow.com/questions/29204113/error-on-using-javax-persistence-joincolumn-foreignkey-annotation-in-code-using