Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA 2.1 load/fetch graph without effect(Lazy attributes remain unloaded regardless of entity graph)
JPA 2.1 load/fetch graph without effect [message #1063959] Sun, 16 June 2013 18:36 Go to next message
Dirk Weil is currently offline Dirk WeilFriend
Messages: 8
Registered: June 2013
Junior Member
The JPA 2.1 load or fetch graphs seem to be without any effect for EclipseLink 2.5.0.

I tried an entity graph named Publisher_books on the entity Publisher. In my understanding it should cause the lazy attribute books - a OneToMany list - to be loaded when using the entity graph as fetch or load graph:

EntityGraph<?> entityGraph = this.entityManager.getEntityGraph("Publisher_books");
TypedQuery<Publisher> query
= this.entityManager.createQuery("select p from Publisher p where p.id=:id",
Publisher.class);
query.setParameter("id", someValidId);
query.setHint("javax.persistence.fetchgraph", entityGraph);
Publisher publisher = query.getSingleResult();

Now, publisher.books should be loaded, but it isn't.

What am I doing wrong?

Thanks!
Dirk
Re: JPA 2.1 load/fetch graph without effect [message #1064292 is a reply to message #1063959] Tue, 18 June 2013 14:52 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

It should be loaded. Check that you have a graph "Publisher_books" defined correctly and that it is not null.

How did you map the relationship (code), and how do you verify it is loaded?

You may also want to try EclipseLink FetchGroup support,

http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_fetchgroup.htm


James : Wiki : Book : Blog : Twitter
Re: JPA 2.1 load/fetch graph without effect [message #1095580 is a reply to message #1064292] Tue, 27 August 2013 08:37 Go to previous messageGo to next message
Dirk Weil is currently offline Dirk WeilFriend
Messages: 8
Registered: June 2013
Junior Member
The relevant part of class Publisher is this:
@Entity
@NamedEntityGraph(
    name = "Publisher_books",
    attributeNodes = @NamedAttributeNode("books"))
public class Publisher extends GeneratedIntegerIdEntity
{
  @OneToMany(mappedBy = "publisher", fetch = FetchType.LAZY)
  private List<Book>         books;


The other side of the relation is class Book:
@Entity
public class Book extends GeneratedIntegerIdEntity
{
  @ManyToOne
  private Publisher          publisher;


The query is executed like this:
EntityGraph<?> entityGraph = this.entityManager.getEntityGraph("Publisher_books");
TypedQuery<Publisher> query = this.entityManager.createQuery("select p from Publisher p where p.id=:id", Publisher.class);
query.setParameter("id", someValidId);
query.setHint("javax.persistence.fetchgraph", entityGraph);
Publisher publisher = query.getSingleResult();


The load status of the attribute is retrieved like this:
PersistenceUtil persistenceUtil = Persistence.getPersistenceUtil();
boolean loaded = persistenceUtil.isLoaded(publisher, "books");


As said, I would expect loaded to be true, but it is false.

The EclipseLink FetchGroup support is no option for me, because I need a valid provider-neutral example for the JPA part of my new book about Java EE 7.

Thanks a lot for any help!
Dirk
Re: JPA 2.1 load/fetch graph without effect [message #1099269 is a reply to message #1095580] Sun, 01 September 2013 12:01 Go to previous message
Dirk Weil is currently offline Dirk WeilFriend
Messages: 8
Registered: June 2013
Junior Member
I isolated a test case. It shows another problem, so I decided to post a new topic - see http://www.eclipse.org/forums/index.php/mv/msg/516119/1099265/#msg_1099265
Previous Topic:(Dead)lock in v2.4.2 with hsqldb and mysql
Next Topic:JPA 2.1 load graph without effect / fetch graph loading wrong fields
Goto Forum:
  


Current Time: Thu Mar 28 22:51:39 GMT 2024

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

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

Back to the top