Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » JPA: EntityGraph -> FetchGroupException when Entity is in another bundle
JPA: EntityGraph -> FetchGroupException when Entity is in another bundle [message #1734478] Wed, 08 June 2016 15:42 Go to next message
Pavel No is currently offline Pavel NoFriend
Messages: 45
Registered: May 2016
Member
I use EclipseLink 2.6.3 as a JPA provider and OSGi.

I have the following code:

String queryString="SELECT a FROM Student a WHERE a.id='"+id+"'";
EntityGraph<Student> eg = em.createEntityGraph(Student.class);
eg.addAttributeNodes("id");
Query query = em.createQuery(queryString);
query.setHint("javax.persistence.fetchgraph", eg);
List<Student> items=query.getResultList();


However, I get exception:
    org.eclipse.persistence.exceptions.QueryException: Exception Description: You must define a fetch group manager at descriptor (com.temp.Student) in order to set a fetch group on the query (null) Query: ReadObjectQuery(referenceClass=Student jpql="SELECT a FROM Student a WHERE a.id='1'") FetchGroup(null){id}


In internet people say that it is necessary to enable weaving, so I added

<property name="eclipselink.weaving" value="true"/>


to my persistence.xml. However, it didn't help.

However, I found out that this problem occurs only when Entity is in another bundle. If it is in the same bundle where persistence.xml file is located everything is ok. How to fix it?

This is stack
at org.eclipse.persistence.exceptions.QueryException.fetchGroupValidOnlyIfFetchGroupManagerInDescriptor(QueryException.java:1305)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.prepareFetchGroup(ObjectLevelReadQuery.java:2079)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.prePrepare(ObjectLevelReadQuery.java:2099)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrePrepare(ObjectLevelReadQuery.java:928)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:822)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
	at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
	at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)


[Updated on: Wed, 08 June 2016 15:47]

Report message to a moderator

Re: JPA: EntityGraph -> FetchGroupException when Entity is in another bundle [message #1734485 is a reply to message #1734478] Wed, 08 June 2016 16:08 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Hi Pavel,

You already know what I am going to say, but I'll say it anyway... Smile

As I mentioned in the other thread, there is no official support for entities being in different bundles. Things may work, but in the end things may not. It looks like weaving may not be happening to the entities in the other bundle. (One way to check is by introspecting the entity to see its attributes.)

My only suggestion to get past that (if that is the problem) is to try static weaving. Look up how to do that in the EclipseLink doc.

-Mike
Re: JPA: EntityGraph -> FetchGroupException when Entity is in another bundle [message #1734486 is a reply to message #1734485] Wed, 08 June 2016 16:12 Go to previous messageGo to next message
Pavel No is currently offline Pavel NoFriend
Messages: 45
Registered: May 2016
Member
Hi Mike

Thank you for your answer. Can you say how I can check if weaving is applied to entity?
Re: JPA: EntityGraph -> FetchGroupException when Entity is in another bundle [message #1734490 is a reply to message #1734486] Wed, 08 June 2016 16:45 Go to previous messageGo to next message
Michael Keith is currently offline Michael KeithFriend
Messages: 243
Registered: July 2009
Senior Member
Introspect the entity class (e.g. getDeclaredFields() method) and you should see some funky EclipseLink-defined attributes prefixed with "_persistence_".
Re: JPA: EntityGraph -> FetchGroupException when Entity is in another bundle [message #1734491 is a reply to message #1734490] Wed, 08 June 2016 16:51 Go to previous message
Pavel No is currently offline Pavel NoFriend
Messages: 45
Registered: May 2016
Member
Thank you very much for your help. Yes the problem was in weaving. I added plugin for static weaving and everything works.
Previous Topic:OSGi access to Apache Tomcat JNDI
Next Topic:EclipseLink: static weaving, inheritance and OSGi
Goto Forum:
  


Current Time: Sun Sep 23 22:32:27 GMT 2018

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

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

Back to the top