-->
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.  [ 1 post ] 
Author Message
 Post subject: Joined-subclass and entity-name cause Duplicate class/entity
PostPosted: Wed Mar 10, 2010 4:46 pm 
Newbie

Joined: Mon Mar 08, 2010 6:15 am
Posts: 2
Hello,

I have a base Card class, that I have mapped using the "entity-name" tag, the goal being to be able to store the same entity differently depending on the context. The mapping is:

Code:
<hibernate-mapping package="org.liveboardgames.agricola.domain.card">
        <class name="Card" table="_CARDS" lazy="false" entity-name="ReferenceCard">
      <id name="cardId" column="CARD_ID">
         <generator class="native" />
      </id>
      <property name="cardName" column="CARD_NAME"/>
                ...
   </class>
   <!-- Different table -->
   <class name="Card" table="CARDS" lazy="false" entity-name="InstanceCard">
      <id name="cardId" column="CARD_ID">
         <generator class="native" />
      </id>
      ...
   </class>
</hibernate-mapping>


This Card class has subclasses, among which ActionCard. The goal here is the same: if I was to handle a Card as a ReferenceCard, I want the ActionCard to be handled as would the ReferenceCard (with possibly additional attributes to store). And same story with InstanceCard.
As a result, I have done the following mapping:

Code:
<hibernate-mapping package="org.liveboardgames.agricola.domain.card">
        <joined-subclass name="ActionCard" extends="ReferenceCard" table="_ACTION_CARDS" entity-name="ReferenceActionCard">
      <key column="CARD_ID"/>
      <property name="period" column="CARD_PERIOD" />
   </joined-subclass>
   <joined-subclass name="ActionCard" extends="InstanceCard" table="ACTION_CARDS" entity-name="InstanceActionCard">
      <key column="CARD_ID"/>
   </joined-subclass>
</hibernate-mapping>


However, when deploying my webapp in my application server, I get the following error:

Quote:
21:22:59,156 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping
ReferenceActionCard
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1302)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
...


As far as I understand, Hibernate does not like my subclassing of the two different entities.
Is there another way?

Thanks for your time,
--
Sébastien


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

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.