-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping different classes oneToMany to one class.Help please
PostPosted: Tue Jan 23, 2007 6:44 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:44 am
Posts: 27
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)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 4:05 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:44 am
Posts: 27
Do I have to save manually the objects C before the A?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:38 am 
Newbie

Joined: Sun Jan 21, 2007 10:56 pm
Posts: 14
fg


Last edited by pali on Wed Jan 24, 2007 7:40 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:39 am 
Newbie

Joined: Sun Jan 21, 2007 10:56 pm
Posts: 14
Can you show us what DAO look like?

from memory, with hibernate, you can set up cascade save?


cheers,


pali


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.