Recursive generics in Hibernate 5

Question

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

interface

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> {
  @Id
  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

@Entity
@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 com.so.AbstractView.children 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 ( 0 )

◀ Go back