-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cannot persist relationship to abstract base class
PostPosted: Tue Jan 14, 2014 8:59 am 
Newbie

Joined: Tue Jan 14, 2014 8:48 am
Posts: 2
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!!!


Top
 Profile  
 
 Post subject: Re: Cannot persist relationship to abstract base class
PostPosted: Tue Jan 14, 2014 4:55 pm 
Newbie

Joined: Tue Jan 14, 2014 8:48 am
Posts: 2
I removed @Table and the Inheritance Strategy (default is single table) and it works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.