Looking at the implementation of Hibernate org.hibernate.jpa.graph.internal.AttributeNodeImpl , we conclude that @NamedAttributeNode cannot be:
- simple types (Java primitives and their wrappers, strings, enumerations, temporary files, ...)
- embeddables (annotated using
@Embedded ) - item collections (annotated using
@ElementCollection )
if (attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.BASIC || attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED ) { throw new IllegalArgumentException( String.format("Attribute [%s] is not of managed type", getAttributeName()) ); }
I did not find a similar limitation in the JPA 2.1 specification, so it may be a flaw in Hibernate.
In your specific case, the problem is that @NamedEntityGraph belongs to the Route class, which is nested, so its use in the entity graph is apparently forbidden by Hibernate (unfortunately).
To make it work, you need to slightly modify the entity model. A few examples that come to my mind:
- define
Route as an object - delete
Route and move its towns field to the Ride object (simplifies the entity model) move the Route field from the Ride to the Town object, add a routedTowns map to the Ride object:
@Entity public class Ride implements Serializable { ... @ManyToMany(mappedBy = "rides") private Map<Route, Town> routedTowns; ... } @Entity public class Town implements Serializable { ... @ManyToMany private List<Ride> rides; @Embeddable private Route route; ... }
Of course, an object graph may require changes accordingly.
source share