|
|
Re: JPA 2.1 load/fetch graph without effect [message #1095580 is a reply to message #1064292] |
Tue, 27 August 2013 08:37 |
Dirk Weil 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02304 seconds