JPA 2.1 load/fetch graph without effect [message #1063959] |
Sun, 16 June 2013 14:36  |
Eclipse User |
|
|
|
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 #1095580 is a reply to message #1064292] |
Tue, 27 August 2013 04:37   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04050 seconds