-->
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: Mapping a Set through a ClassComponent ?
PostPosted: Thu Jun 01, 2006 5:40 am 
Newbie

Joined: Wed May 31, 2006 5:01 am
Posts: 5
I got a UML diagram that looks like this:

Member<-----have one------>MemberAccount<-----subscribe to many----->Group

so i mapped it like that:

Class--------------------------------Component-------------------------------------Set

it's obviously a bidirectionnal many-to-many association between Group and MemberAccount:
Here's partially my mappings files :

1. Group.hbm.xml
<class
<set name="memberAccount" table="users_groups" lazy="true"
inverse="true" cascade="save-update">
<key column="group_id" />
<many-to-many class="src.users.Member" column="user_id"></many-to-many>
</set>

2. Member.hbm.xml
<component name="MemberAccount" class="src.accounts.MemberAccount">
<property name="status" type="string" />
<property name="creationDate" type="date" update="false"/>
<set name="myGroups" table="users_groups" lazy="true">
<key column="user_id" />
<many-to-many class="src.groups.Group" column="group_id">
</many-to-many>
</set>
</component>

But here's the problem : I create a member with its account, I create a group, I associate them
group.addMemberAccount(this);
myGroups.add(group);
and after the storage, i load the the too objects. I retrieved the group from the member passing through the component account BUT cannot do the opposite.

How can I do, any example for such mapping ???

here's the logs
[CascadingAction] cascading to saveOrUpdate: src.users.Member
Exception in thread "main" org.hibernate.HibernateException: instance not of expected entity type: src.users.Member
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3301)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1311)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:460)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at src.tests.HibernateTest.associateGroupMember(HibernateTest.java:118)
at src.tests.HibernateTest.scenario1(HibernateTest.java:39)
at src.tests.HibernateTest.main(HibernateTest.java:20)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 8:39 am 
Newbie

Joined: Wed May 31, 2006 5:01 am
Posts: 5
I don't now if my problem is clear.....

To say it simplier : Is it possible to map a Set into a Component and have a "real" bidirectionnal many-to-many association?

<class name="src.users.Member" discriminator-value="member">
<component name="memberAccount" class="src.accounts.MemberAccount">
<property name="status" type="string"/>
<property name="creationDate" type="date" insert="false"
update="false" />
<set name="myGroups" table="users_groups"
lazy="true" cascade="save-update">
<key column="user_id" />
<many-to-many class="src.groups.Group" column="group_id">
</many-to-many>
</set>
</component>


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.