Hello there! We have encountered an issue when upgrading to spring boot 3, and it seems to be caused by Hibernate. Hopefully this is the right place to report it. When fetching a ManyToMany relationship which has an `@OrderBy` annotation present, and is a subclass, with JOINED inheritence type, hibernate throws a `UnknownTableReferenceException`:
Here are the entity classes:
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@CreatedDate
protected Instant createdAt = Instant.now();
}
@MappedSuperclass
public abstract class AnimalBase extends BaseEntity {
protected String name;
protected String species;
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "animals")
public class Animal extends AnimalBase {
private transient String unrelatedThing;
}
@Entity
@Table(name = "dogs")
public class Dog extends Animal {
private int barkIntensity;
}
@Entity
@Table(name = "humans")
public class Human extends BaseEntity {
private String humanName;
@ManyToMany()
@OrderBy("name")
@JoinTable(name = "human_pet",
inverseJoinColumns = @JoinColumn(name = "pet_id", referencedColumnName = "id"),
joinColumns = @JoinColumn(name = "human_id", referencedColumnName = "id"))
private Set<Dog> pets = new LinkedHashSet<>();
}
@Entity
@Table(name = "id_cards")
public class IdCard extends BaseEntity {
private Long serial;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(unique = true)
private Human human;
}
And finally, the query which gets called
public interface IdCardRepository extends JpaRepository<IdCard, Long> {
@Query("select ic from IdCard ic " +
"left join fetch ic.human as h " +
"left join fetch h.pets")
IdCard find(Long id);
}
Removing either the @OrderBy or the inheritance makes the exception disappear. Here is a reproduction repo |