Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Composite persistence unit and JPQL

Michael Oberleitner
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:

--- websocket
--- ...
--- Book.class
--- 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(
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(
at kma88.websocket.jsf.BookService.onLoad(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.sun.el.parser.AstValue.invoke(
at com.sun.el.MethodExpressionImpl.invoke(
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(
at org.jboss.weld.el.WeldMethodExpression.invoke(
at com.sun.faces.facelets.el.TagMethodExpression.invoke(
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(
at javax.faces.event.SystemEvent.processListener(
at javax.faces.event.ComponentSystemEvent.processListener(
at com.sun.faces.application.ApplicationImpl.processListeners(
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(
at com.sun.faces.application.ApplicationImpl.publishEvent(
at com.sun.faces.application.ApplicationImpl.publishEvent(
at javax.faces.application.ApplicationWrapper.publishEvent(
at com.sun.faces.lifecycle.RenderResponsePhase.execute(
at com.sun.faces.lifecycle.Phase.doPhase(
at com.sun.faces.lifecycle.LifecycleImpl.render(
at javax.faces.webapp.FacesServlet.service(
at org.apache.catalina.core.StandardWrapper.service(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardPipeline.doInvoke(
at org.apache.catalina.core.StandardPipeline.invoke(
at com.sun.enterprise.web.WebPipeline.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.doService(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.glassfish.grizzly.http.server.HttpHandler.runService(
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(
at org.glassfish.grizzly.ProcessorExecutor.execute(
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(
at org.glassfish.grizzly.threadpool.AbstractThreadPool$

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: 34
  • Mark post as helpful
  • send pies
  • 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!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic