I’m receiving the exception InvalidDataAccessResourceUsageException with the following message: “Could not solve attribute ‘field’ of ‘Parent’ class due to the attribute being declared in multiple subtypes ‘ChildOne’ and ‘ChildTwo'”.
The example code is the following:
@Entity
@Table(schema = "example", name = "parent")
@Inheritance(strategy = InheritanceType.JOINED)
public class Parent {
...
}
@Entity
@Table(schema = "example", name = "relation_class")
public class RelationClass {
...
}
@Entity
@Table(schema = "example", name = "child_one")
public class ChildOne extends Parent {
@ManyToOne
@JoinColumn(name = "relation_id")
RelationClass field;
...
}
@Entity
@Table(schema = "example", name = "child_two")
public class ChildTwo extends Parent {
@ManyToOne
@JoinColumn(name = "relation_id")
RelationClass field;
...
}
public class ClassSpecification{
...
private static void createJoin(List<Predicate> predicates, CriteriaBuilder cb, Root<Parent> root) {
Join<RelationClass, Parent> join = root.join("field", JointType.LEFT);
}
...
}
When making a Join using a field from a child table of a parent table with @Inheritance(strategy = InheritanceType.JOINED) I received a message saying that the JPA could not determine from which child the field should come.
I need the @Inheritance annotation and the root to be of the type Parent.
I believe that in order to fix this issue I would need to specify from which child class the data should come from, but I don’t know how to do this in the join method.