I saw similar issues where people had to make concrete classes (X and Y here) to implement Serializable
in order to make it work
Hibernate Cannot instantiate abstract class or interface
-
31-05-2023 - |
Domanda
I have following project:
@Entity
@Table(name = "A")
public class A{
@Id
private Long id = null;
@OneToMany(mappedBy = "a_1", cascade = CascadeType.ALL,
fetch = FetchType.EAGER)
private List<B> bs;
}
@Entity
@Table(name = "B")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "BTYPE",
discriminatorType = DiscriminatorType.STRING)
public abstract class B{
@Id
private Long id = null;
@Embedded
private C c;
@ManyToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="a_id")
@XmlTransient
private A a_1;
}
@Embeddable
public class C {
@OneToMany(mappedBy = "b_1", cascade = CascadeType.ALL,
fetch = FetchType.EAGER))
private Set<D> ds;
}
@Entity
@Table(name = "D")
public class D {
@ManyToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="b_id")
private B b_1;
}
@Entity
@DiscriminatorValue(value = "X_D")
public class X extends B {
}
@Entity
@DiscriminatorValue(value = "Y_D")
public class Y extends B {
}
All these classes implement Serializable except X and Y
At the moment when I call entityManager.merge(A) I get:
Caused by: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: B
Can anybody helpe me please?
Thnaks in advance
Nessuna soluzione corretta
Altri suggerimenti
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow