Entities not being detected when using packaged Hibernate JPA persistence provider












0















Im deploying my web application on a local wildfly-11.0.0.Final
server.
Wildfly however provides its own hibernate and jpa modules which I
dont want to use. I want to use the jpa jars packaged with my
application.



As described in
https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication
I added the line



<property name="jboss.as.jpa.providerModule" value="application"/>



to my persistence.xml



Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like



<class>com.mycompany.mywebapp.Actor</class>



Is there any way to fix this?



I tried



<jar-file></jar-file>



and



<property name="hibernate.archive.autodetection" value="class, hbm"/>



without success.



My persistence.xml looks like this:



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA">
<jta-data-source>java:/jboss/sakila</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="jboss.as.jpa.providerModule" value="application"/>
</properties>
</persistence-unit>
</persistence>


Edit:



Im using hibernate 5.3.7.Final which implements jpa 2.2.



My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.



Edit 2:



I noticed that even though the hibernate version is now 5.3.7.Final the jpa provided by wildfly (specification version 2.1) is still being used which may be causing this issue.



I tried disabling the wildfly modules in a jboss-deployment-structure.xml:





<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" />
<module name="javax.persistence.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>


However now im facing following error:



Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."webapp-1.0.war".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "webapp-1.0.war" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0019: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider' Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider"}}


Edit 3:



To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.



Anyway I would like to know how I can fix the issue of my packaged jpa jar not being used and how to make my entities be automatically detected again. Any hints?










share|improve this question

























  • The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

    – coladict
    Jan 2 at 6:04











  • I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

    – User5458751
    Jan 2 at 6:38













  • Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

    – Steve C
    Jan 2 at 8:46











  • No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

    – User5458751
    Jan 2 at 9:20











  • With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

    – coladict
    Jan 3 at 21:21


















0















Im deploying my web application on a local wildfly-11.0.0.Final
server.
Wildfly however provides its own hibernate and jpa modules which I
dont want to use. I want to use the jpa jars packaged with my
application.



As described in
https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication
I added the line



<property name="jboss.as.jpa.providerModule" value="application"/>



to my persistence.xml



Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like



<class>com.mycompany.mywebapp.Actor</class>



Is there any way to fix this?



I tried



<jar-file></jar-file>



and



<property name="hibernate.archive.autodetection" value="class, hbm"/>



without success.



My persistence.xml looks like this:



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA">
<jta-data-source>java:/jboss/sakila</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="jboss.as.jpa.providerModule" value="application"/>
</properties>
</persistence-unit>
</persistence>


Edit:



Im using hibernate 5.3.7.Final which implements jpa 2.2.



My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.



Edit 2:



I noticed that even though the hibernate version is now 5.3.7.Final the jpa provided by wildfly (specification version 2.1) is still being used which may be causing this issue.



I tried disabling the wildfly modules in a jboss-deployment-structure.xml:





<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" />
<module name="javax.persistence.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>


However now im facing following error:



Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."webapp-1.0.war".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "webapp-1.0.war" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0019: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider' Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider"}}


Edit 3:



To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.



Anyway I would like to know how I can fix the issue of my packaged jpa jar not being used and how to make my entities be automatically detected again. Any hints?










share|improve this question

























  • The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

    – coladict
    Jan 2 at 6:04











  • I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

    – User5458751
    Jan 2 at 6:38













  • Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

    – Steve C
    Jan 2 at 8:46











  • No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

    – User5458751
    Jan 2 at 9:20











  • With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

    – coladict
    Jan 3 at 21:21
















0












0








0








Im deploying my web application on a local wildfly-11.0.0.Final
server.
Wildfly however provides its own hibernate and jpa modules which I
dont want to use. I want to use the jpa jars packaged with my
application.



As described in
https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication
I added the line



<property name="jboss.as.jpa.providerModule" value="application"/>



to my persistence.xml



Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like



<class>com.mycompany.mywebapp.Actor</class>



Is there any way to fix this?



I tried



<jar-file></jar-file>



and



<property name="hibernate.archive.autodetection" value="class, hbm"/>



without success.



My persistence.xml looks like this:



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA">
<jta-data-source>java:/jboss/sakila</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="jboss.as.jpa.providerModule" value="application"/>
</properties>
</persistence-unit>
</persistence>


Edit:



Im using hibernate 5.3.7.Final which implements jpa 2.2.



My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.



Edit 2:



I noticed that even though the hibernate version is now 5.3.7.Final the jpa provided by wildfly (specification version 2.1) is still being used which may be causing this issue.



I tried disabling the wildfly modules in a jboss-deployment-structure.xml:





<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" />
<module name="javax.persistence.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>


However now im facing following error:



Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."webapp-1.0.war".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "webapp-1.0.war" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0019: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider' Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider"}}


Edit 3:



To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.



Anyway I would like to know how I can fix the issue of my packaged jpa jar not being used and how to make my entities be automatically detected again. Any hints?










share|improve this question
















Im deploying my web application on a local wildfly-11.0.0.Final
server.
Wildfly however provides its own hibernate and jpa modules which I
dont want to use. I want to use the jpa jars packaged with my
application.



As described in
https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-PackagingtheHibernateJPApersistenceproviderwithyourapplication
I added the line



<property name="jboss.as.jpa.providerModule" value="application"/>



to my persistence.xml



Now however my entites (Annotated with @Entity) are not being detected anymore and I have to explicitly name them in my persistence.xml like



<class>com.mycompany.mywebapp.Actor</class>



Is there any way to fix this?



I tried



<jar-file></jar-file>



and



<property name="hibernate.archive.autodetection" value="class, hbm"/>



without success.



My persistence.xml looks like this:



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="com.mycompany_mywebapp_war_1.0PU" transaction-type="JTA">
<jta-data-source>java:/jboss/sakila</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="jboss.as.jpa.providerModule" value="application"/>
</properties>
</persistence-unit>
</persistence>


Edit:



Im using hibernate 5.3.7.Final which implements jpa 2.2.



My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.



Edit 2:



I noticed that even though the hibernate version is now 5.3.7.Final the jpa provided by wildfly (specification version 2.1) is still being used which may be causing this issue.



I tried disabling the wildfly modules in a jboss-deployment-structure.xml:





<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" />
<module name="javax.persistence.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>


However now im facing following error:



Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."webapp-1.0.war".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "webapp-1.0.war" Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0019: Could not deploy application packaged persistence provider 'org.hibernate.jpa.HibernatePersistenceProvider' Caused by: java.lang.ClassCastException: class org.hibernate.jpa.HibernatePersistenceProvider"}}


Edit 3:



To test whether this is the cause for my initial problem I manually replaced the jpa jar. Unfortunately this doesnt solve my problem.



Anyway I would like to know how I can fix the issue of my packaged jpa jar not being used and how to make my entities be automatically detected again. Any hints?







java hibernate jpa wildfly persistence.xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 7:30







User5458751

















asked Jan 1 at 21:35









User5458751User5458751

12




12













  • The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

    – coladict
    Jan 2 at 6:04











  • I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

    – User5458751
    Jan 2 at 6:38













  • Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

    – Steve C
    Jan 2 at 8:46











  • No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

    – User5458751
    Jan 2 at 9:20











  • With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

    – coladict
    Jan 3 at 21:21





















  • The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

    – coladict
    Jan 2 at 6:04











  • I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

    – User5458751
    Jan 2 at 6:38













  • Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

    – Steve C
    Jan 2 at 8:46











  • No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

    – User5458751
    Jan 2 at 9:20











  • With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

    – coladict
    Jan 3 at 21:21



















The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

– coladict
Jan 2 at 6:04





The persistence.xml and the entity classes need to be in the same file tree. Meaning the either in the root war file, or in the same jar file. If you can't restructure it like that, then you need to list the entity classes in the xml.

– coladict
Jan 2 at 6:04













I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

– User5458751
Jan 2 at 6:38







I dont think thats the issue. My classes are in mywebapp-1.0.warWEB-INFclassescommycompanymywebapp and my persistence.xml in mywebapp-1.0.warWEB-INFclassesMETA-INF My entites have been detected correctly when not using the packaged jpa persistence provider. I tried having my entities in a seperate jar and use <jar-file>lib/data.jar</jar-file> in my persistence.xml without succes.

– User5458751
Jan 2 at 6:38















Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

– Steve C
Jan 2 at 8:46





Does the version of Hibernate that you want to use implement the same version of JPA as that provided by WildFly 11?

– Steve C
Jan 2 at 8:46













No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

– User5458751
Jan 2 at 9:20





No. Im using hibernate 5.3.7.Final which implements jpa 2.2. My wildfly server provides hibernate 5.1.10.Final with jpa 2.1.

– User5458751
Jan 2 at 9:20













With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

– coladict
Jan 3 at 21:21







With the edit that shows the error we see the problem. When you have a ClassCastException with a class not being able to cast to itself, then you have a classloader problem. Two classloaders have loaded the same class from two different jars. One loaded it from Wildfly, the other from Hibernate. You need to remove or disable the embedded version. This wiki entry should help.

– coladict
Jan 3 at 21:21














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999124%2fentities-not-being-detected-when-using-packaged-hibernate-jpa-persistence-provid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999124%2fentities-not-being-detected-when-using-packaged-hibernate-jpa-persistence-provid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas