The question about using fetchgraph [message #1731549] |
Fri, 06 May 2016 17:10 |
Pavel No Messages: 47 Registered: May 2016 |
Member |
|
|
I have the following entity:
@Entity
@Table(name = "tbl1")
public class PersonItem implements Serializable{
@Id
@Column(name="col1")
private String guid;
@Column(name="col2")
private String name;
@Column(name="col3")
private String surname;
@Column(name="col4")
private Date birthDate;
//+getters and setters
}
And I want that only three fields of 4 were loaded from DB. So I do:
Query query = em.createQuery("Select p from PersonItem p");
EntityGraph<PersonItem> eg = em.createEntityGraph(PersonItem.class);
eg.addAttributeNodes("guid");
eg.addAttributeNodes("name");
eg.addAttributeNodes("surname");
query.setHint("javax.persistence.fetchgraph", eg);
List<PersonItem> list=query.getResultList();
Everything works ok and I see in log that only 3 columns are selected. However, when I try to do item.getBirthDate then istead of null or exception the execution of the thread totally stops, so the next statement after item.getBirthDate is not executed. Why, and how can it be fixed?
[Updated on: Fri, 06 May 2016 17:48] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03188 seconds