Description
Hi there,
during the update to spring boot 3.x i encountered some issues related to generic types used in entities. I reported a bug in hibernate-core (Jira), which was fixed as part of spring boot 3.2.1 (hibternate 6.4.1) but now my jpa repositories are the next ones, that are not happy with my implementation.
Lets assume we have 2 abstract classes Parent and Child, that know each other
@Data
@MappedSuperclass
public abstract class Parent<C extends Child<?>> {
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<C> children = new LinkedList<>();
public abstract Long getId();
public abstract void setId(Long id);
}
@Data
@MappedSuperclass
public abstract class Child<P extends Parent<?>> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(optional = false)
private P parent;
}
And we have multiple implementations of them
@Data
@Entity
public class ParentA extends Parent<ChildA> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
@Data
@Entity
public class ParentB extends Parent<ChildB> {
@Id
private Long id;
}
@Data
@Entity
public class ChildA extends Child<ParentA> {
}
@Data
@Entity
public class ChildB extends Child<ParentB> {
}
The ids of the parents are not specified in the abstract class cause i need different generation strategies depending on the specific type.
And then we have a repository interface for children, all specific-type-repositories are inheriting:
@NoRepositoryBean
public interface ChildRepository<C extends Child<?>> extends JpaRepository<C, Long> {
boolean existsByIdAndParentId(Long id, Long parentId);
}
I will work with this ChildRepository in an abstract service.
If i try to execute the "extistsByIdAndParentId" method, i'll get the following exception
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [id] on this ManagedType [com.hibernate.data.core.Parent]
But this kind of inheritance worked in my previous version using spring boot version 2.6.1
I've attached a application of this simplified usecase, where you can recreate my problem
spring-data.zip
Thanks!
Denis