This is my entity:
Code:
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
}
This is how I get the list of persons:
Code:
Query query = em.createQuery("Select p from PersonItem p WHERE p.guid IN (:guids)");
EntityGraph<PersonItem> eg = em.createEntityGraph(PersonItem.class);
eg.addAttributeNodes("guid");
eg.addAttributeNodes("name");
eg.addAttributeNodes("surname");
query.setHint("javax.persistence.fetchgraph", eg);
query.setParameter("guids", guids);
List<PersonItem> list=query.getResultList();
em.close();
// And now I iterate result AFTER EM CLOSE
....iterate
If I understand fetch graph correcly it must load only those fields, which I specified. However, the field "birthDate" is also loaded. Besides I see that in hibernate sql query 4 columns are selected.
How to fix it? I use hibernate 5.1.0 as JPA provider. People say that according to JPA this must work
http://stackoverflow.com/a/37053402/5057736