Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » (Composite) persistence.xml: NamedQuery of name XYZ not found.(Background: Java EE Modularization)
icon9.gif  (Composite) persistence.xml: NamedQuery of name XYZ not found. [message #1207999] Sun, 24 November 2013 22:03 Go to next message
Martin S. is currently offline Martin S.Friend
Messages: 5
Registered: July 2009
Junior Member
Hello everybody,

I am in the process of modularizing a Java EE application (Java EE 7, Glassfish 4, JPA 2.1, EclipseLink 2.5). Everything worked fine so far, but I am currently experiencing a showstopper.

---

Scenario:

I have an EAR called "myApp.ear" that has dependencies to two EJB/Entity modules represented as JARs called "myModule1.jar" and "myModule2.jar". "myModule2.jar" is also dependent of "myModule1.jar". Each module defines its own persistence.xml in META-INF. The EAR also defines a persistence.xml which serves as the composite persistence.xml.

I have configured everything as explained in the EclipseLink doc.

Everything is working fine: Interaction with JSF modules, EntityManager operations like find(), persist(), etc. Except one thing is constantly going wrong trying to use a named query: "NamedQuery of name XYZ not found". The named queries are all defined in the entities via @NamedQuery. In the unmodularized recent version of the application they are all working fine, I have not changed the original and working code at any point.

I have altered almost every possible setting in the persistence.xml´s like <class>, <mapping-file> and so on. I have varied the persistence.xml´s to death, tried all and everything I could think of, searched the net a hundred times, but sadly there is no solution in sight. I don´t care how I am getting my modularized app to work, I just want it to work without "NamedQuery of name XYZ not found". Any help is greatly appreciated. Here are my persistence units:

------------------------------------

"myApp.ear":

    <persistence-unit name="myApp" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>  
        <validation-mode>CALLBACK</validation-mode>    
        <jar-file>myModule1.jar</jar-file>
        <jar-file>myModule2.jar</jar-file>       
        <exclude-unlisted-classes>false</exclude-unlisted-classes>  
        <properties>
            <property name="eclipselink.application-location" value="E:\_dirsync\_snc\htdocs\snc\snc-ejb\src\java\de\blacksmiths\snc\backend\sql\" />
            <property name="eclipselink.composite-unit" value="true"/>
            <property name="eclipselink.create-ddl-jdbc-file-name" value="ddl_create.sql"/>
            <property name="eclipselink.ddl-generation" value="create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="both"/>
            <property name="eclipselink.drop-ddl-jdbc-file-name" value="ddl_drop.sql"/>
            <property name="eclipselink.logging.level" value="FINE"/>
            <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/>
        </properties>
    </persistence-unit>


------------------------------------

"myModule1.jar":

    <persistence-unit name="myModule1" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myConnectionPool</jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
        <class>de.snc.backend.auth.entity.Auth</class>
        <class>de.snc.backend.user.entity.User</class>  
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    </persistence-unit>


------------------------------------

"myModule2.jar":

    <persistence-unit name="myModule2" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myConnectionPool</jta-data-source>
        <mapping-file>META-INF/orm.xml</mapping-file>
        <class>de.snc.backend.user.entity.User</class>  
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    </persistence-unit>


------------------------------------
Re: (Composite) persistence.xml: NamedQuery of name XYZ not found. [message #1212343 is a reply to message #1207999] Tue, 26 November 2013 21:39 Go to previous messageGo to next message
Martin S. is currently offline Martin S.Friend
Messages: 5
Registered: July 2009
Junior Member
Surely also of interest, the stacktrace:
java.lang.IllegalArgumentException: NamedQuery of name: User.selectByEmail not found.
at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:350)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1107)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:522)
at de.snc.backend.core.control.GenericQueryService.findWithNamedQuery(GenericQueryService.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 97 more

[Updated on: Tue, 26 November 2013 21:40]

Report message to a moderator

Re: (Composite) persistence.xml: NamedQuery of name XYZ not found. [message #1217331 is a reply to message #1212343] Thu, 28 November 2013 21:56 Go to previous messageGo to next message
Martin S. is currently offline Martin S.Friend
Messages: 5
Registered: July 2009
Junior Member
I´ve spent another several hours to find a solution ... no luck so far.

Can someone please tell me if my approach is common and valid.
Did I make a mistake configuring composite persistence.xml and member persistence.xml?
Are there any other approaches out there modularizing a Java EE App (1 Module = 1 Jar)? Maybe without composite persistence.xml?

Also it seems that I am not the only one facing these kind of problems:
http://www.eclipse.org/forums/index.php/mv/msg/488417/1061905/#msg_1061905

Any help is greatly appreciated.
Re: (Composite) persistence.xml: NamedQuery of name XYZ not found. [message #1219088 is a reply to message #1207999] Sun, 01 December 2013 16:58 Go to previous messageGo to next message
Martin S. is currently offline Martin S.Friend
Messages: 5
Registered: July 2009
Junior Member
Very interesting, when I add

<properties>
 <property name="eclipselink.composite-unit.member" value="true"/>
</properties>


to the persistence.xml of "myModule1" and "myModule2" I get the following exception:

SEVERE:   Exception while deploying the app [myApp] : Exception [EclipseLink-28030] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: PersistenceUnit [myModule1] specifies eclipselink.composite-unit.member property with value true. That means it cannot be used standalone, but only as a composite member.


It seems that composite persistence.xml does not even get recognized by Glassfish. I really don´t get it ...

Where do I have to put the composite persistence.xml so that it gets recognized? I suppose that it should be sufficient putting it in "myApp.ear/META-INF/persistence.xml"?

Re: (Composite) persistence.xml: NamedQuery of name XYZ not found. [message #1219967 is a reply to message #1219088] Sat, 07 December 2013 15:57 Go to previous message
Martin S. is currently offline Martin S.Friend
Messages: 5
Registered: July 2009
Junior Member
Ok, this was somehow a fight, but finally it works (although I am not using composite persistence units any more).

If anyone is searching for a solution to modularize a Java EE 7 application that will be deployed to Glassfish, these are very good references:

monica2nto.wordpress.com/2012/01/18/dal-modularizada-en-jpa-con-un-unico-persistenceunit-j2ee/
-> It´s in Spanish, but just translate in a language you understand (e.g. via Google Chrome). The explanations for Websphere also work for Glassfish 4.

stackoverflow.com/a/14971161
stackoverflow.com/a/4076433
-> The same solution as adove, just in other words Wink

If you want any further explanations modularizing the web tier take a look at this, it helped me a lot:
ocpsoft.org/java/jsf-java/how-to-modular-jsf-applications-with-cdi-and-prettyfaces/
stackoverflow.com/a/8320738

Have fun!

[Updated on: Sat, 07 December 2013 16:15]

Report message to a moderator

Previous Topic:MOXy Performance and Caching
Next Topic:Run time error for DALI generated entity with compound keys
Goto Forum:
  


Current Time: Thu Nov 27 05:40:59 GMT 2014

Powered by FUDForum. Page generated in 0.02015 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software