• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite persistence unit and JPQL

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I developed a small application using JPA for persistence and using container managed security for authentication and authorization on Glassfish 4.
The application uses two persistence units, one for the application data and one for authentication. For authentication I have a custom jdbc realm
in Glassfish and it works all fine for login and the roles get assigned to the logged in users.
Now i also wanted to register users with the application in the custom realm and so I splitted the persistence unit in one composite persistence unit
and two persistence unit members.

composite persistence unit:


Also I created the two jar files app and sec jar, which both have this structure:

kma88
|
--- websocket
|
--- ...
|
--- Book.class
META-INF
|
--- MANIFEST.MF
|
--- persistence.xml

and the persistence xml for the app.jar looks like this:


this is persistence.xml of sec.jar:


The source of the book class is here:


and this is a part of the book dao:

Now when I deploy the application it seems to work fine, but during deploying I realized those two warnings:
2016-05-23T11:28:34.803+0200|Warnung: PER02000: PersistenceUnitInfoImpl: For pu-root [C:\glassfish4\glassfish\domains\domain1\eclipseApps\JTA-ExampleWithGlassfish4\WEB-INF\classes], a jar-file [app.jar] specified in persistence.xml is not found. The server also looked for a file called [C:\glassfish4\glassfish\domains\domain1\eclipseApps\JTA-ExampleWithGlassfish4\WEB-INF\app_jar]. Please verify your application.
2016-05-23T11:28:34.804+0200|Warnung: PER02000: PersistenceUnitInfoImpl: For pu-root [C:\glassfish4\glassfish\domains\domain1\eclipseApps\JTA-ExampleWithGlassfish4\WEB-INF\classes], a jar-file [sec.jar] specified in persistence.xml is not found. The server also looked for a file called [C:\glassfish4\glassfish\domains\domain1\eclipseApps\JTA-ExampleWithGlassfish4\WEB-INF\sec_jar]. Please verify your application.

Now when calling the application I get following exception:
2016-05-23T11:29:57.339+0200|Warnung: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalArgumentException: NamedQuery of name: Book.findAvailableBooks not found.
at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:355)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1135)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1155)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:545)
at kma88.websocket.jsf.BookService.onLoad(BookService.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

So I changed the settings for the deployment assembly in eclipse to deploy the both jar files which are located in WEB-INF/lib/ and also added to the java build path of eclipse, to deploy to /WEB-INF/classes/ respectively /WEB-INF/ according to the warning mentioned above and I also checked if the jars are really deployed to this locations, but they are there.

So made a new approach with creation of entity-mappings.xml for the app.jar, because this is the part, where the first error occurs. I changed persistence.xml to this:


and the app.xml in the jpql folder is this:


But still no difference the above warnings are still there, even though the jars get deployed.
So I wonder if it is not possible to use named queries in composite persistence unit members. I read about @namedstoredfunctionquery and switching to stored functions, but this seems inconvenient to me, because I want to maintain portability to different databases servers. Or is it better to use criteria or dynamic queries or something like this. What is the best practice in a case like this.

Any help is appreciated!




 
Michael Oberleitner
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok no replies so far. Maybe I explain what I want to achieve, because I think this should be a common task and maybe I'm completely wrong with my approach.
I want to use a glassfish jdbc-realm separated from the rest of the application data, which is in in a different database, but entitys of boths sides are related to each other.

For example the logged in user is stored in the realm and articles are in the application database and both have relations with each other.
I'm interested in what is best practice in such a case!
 
reply
    Bookmark Topic Watch Topic
  • New Topic