Recursive generics in Hibernate 5


My project is migrating to hibernate 5 from 4.3 And we have some entities with recursive generics, like this:


public interface HierarchicalEntity<T extends HierarchicalEntity<T>> {

  Collection<? extends T> getChildren();

  T getParent();


abstract class

public abstract class AbstractView<T extends HierarchicalEntity<T>> implements HierarchicalEntity<T> {
  private Long id;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumns({@JoinColumn(name = "parentId")})
  private T parent;
  @Column(insertable = false, updatable = false)
  private Long parentId;
  @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
  Set<T> children;

and concrete class

@Table(name = "v_concrete")
public class ConcreteView extends AbstractView<ConcreteView> {

And this configuration works perfectly well on hibernate 4.3.11 But we decided to move to 5.0.11 and after changing version (and reconfiguring naming strategies) this approach no longer works! When i try to run project, I Got following error

AnnotationException: Property has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type

I can't figure out why. Why this approach works with 4.3.11 and does not with 5.0.11 ?

Show source
| generics   | java   | spring-data-jpa   | hibernate   | jpa   2017-01-05 15:01 0 Answers

Answers to Recursive generics in Hibernate 5 ( 0 )

Leave a reply to - Recursive generics in Hibernate 5

◀ Go back