For demonstration purposes, I created the below example. If I try to use a named entity graph with “{{LazyEntity.stringOnly}}“, or “{{LazyEntity.childrenOnly}}“. It works fine. But I try to use “{{LazyEntity.stringAndChildren}}“ it only loads the “children” not “string” property. I also attached an example project.
{code:java}@Entity @Table(name = "lazy") @NamedEntityGraph( name = "LazyEntity.stringOnly", attributeNodes = { @NamedAttributeNode("string"), } ) @NamedEntityGraph( name = "LazyEntity.childrenOnly", attributeNodes = { @NamedAttributeNode("children"), } ) @NamedEntityGraph( name = "LazyEntity.stringAndChildren", attributeNodes = { @NamedAttributeNode("string"), @NamedAttributeNode("children"), } ) public class LazyEntity {
@Id private Long id;
@Basic(fetch = FetchType.LAZY) private String string;
@OrderBy("createdAt DESC") @OneToMany(mappedBy = "parent") private List<LazyChild> children;
// getter setters ommited }{code}
If I run the example project with {{mvn compile exec:java}} command, This output will display. it says when the named entity graph “{{LazyEntity.stringAndChildren}}“ not working correctly.
{noformat}LazyEntity.stringAndChildren string: false children: true LazyEntity.stringOnly string: true children: false LazyEntity.childrenOnly string: false children: true{noformat} |
|