Hi!
How do I have to map the following configuration without superclass for :
ClassA with as field List<ClassC>
ClassB with as field List<ClassC>
in database :
+--------------+----------+
| objectA_id | ... |
+--------------+----------+
| 1 | ... |
| 2 | |
+--------------+----------+
+--------------+----------+
| objectB_id | ... |
+--------------+----------+
| 1 | ... |
+--------------+----------+
+--------------+----------+----------+----------+
| objectC_id | ... | class | id_FK |
+--------------+----------+----------+----------+
| 1 | | A | 1 |
| 2 | | B | 1 |
| 3 | | A | 2 |
| 4 | | A | 2 |
| 5 | | B | 1 |
| 6 | | A | 2 |
+--------------+----------+----------+----------+
Thanks!
Hibernate version: 3.2
Mapping documents:
Code:
<?xml version='1.0'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" default-lazy="false">
<class name="ClassC" table="T_objectC">
<id name="id" column="objectC_id" type="long" unsaved-value="null">
<generator class="increment"/>
</id>
<version column="version" name="version" type="long"/>
<property name="comment" column="comment" type="string" length="999" not-null="true"/>
<property name="date" column="date" type="org.joda.time.contrib.hibernate.PersistentDateTime"/>
<property name="user" column="user_loginName" type="string" length="100" not-null="true"/>
</class>
</hibernate-mapping>
Code:
<?xml version='1.0'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" default-lazy="false">
<class name="ClassA" table="T_objectA">
<id name="id" column="objecA_id">
<generator class="increment"/>
</id>
<version name="version" column="version" type="long" />
<bag name="listC" table="T_objectC" order-by="date" inverse="false" cascade="all">
<key>
<column name="id_FK"/>
<!--column name="classType"-->
</key>
<one-to-many class="ClassC"/>
</bag>
....
Full stack trace of any exception that occurs:
[code]
Exception in thread "AWT-EventQueue-0" org.springframework.dao.InvalidDataAccessApiUsageException: ClassC; nested exception is org.hibernate.TransientObjectException: be.mil.cccis.atdl3.dto.Remark
org.hibernate.TransientObjectException: ClassC
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:697)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1037)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy50.create(Unknown Source)