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