Hi,
I know: a lot of questions have already been asked related to my issue. However, I do not find the solution related to my problem. I hope somebody can help me on my specific issue.
I need to persist an objectmodel which consists of a relationship to an abstract class. Whenever hibernate tries to store this relationship I receive the following error and stack trace:
Code:
Caused by: javax.persistence.PersistenceException: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: de.thorsten.model.SportsEvent
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl
...
at org.jboss.weldx.persistence.EntityManager$-100333838$Proxy$_$$_Weld$Proxy$.merge(EntityManager$-100333838$Proxy$_$$_Weld$Proxy$.java)
at de.thorsten.service.ParticipationService.update(ParticipationService.java:32)
...
I do have a relation between "Participation" and "SportsEvent" (which is the abstract class). In this example the relationship is between "Participation" and the concrete subclass "Training".
The error happens when the following service is invoked:
Code:
@Stateless
public class ParticipationService implements Serializable {
@Inject
private EntityManager em;
public void update(Participation participation) throws Exception {
em.merge(participation); // this statement fires the exception !
}
}
The fragments below shows the related code snippets
// The abstract root class:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "eventDate"))
public abstract class SportsEvent implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;
@NotNull
protected Date eventDate;
//...
}
// The concrete subclass
@Entity
public class Training extends SportsEvent implements Serializable {
public Training() {
}
@OneToOne
private TrainingDay trainingDay;
//...
}
// The class which owns the relationship to the abstract base class
@Entity
public class Participation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne
private SportsEvent trainingItem; // participating this relationship does not work !
//...
}
I tried already different inheritance strategies but got the same result.
Does someboy know what needs to be done to get this work ? Thanks in advance for your help!!!