-->
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: Update von bidirektional verknüpften Objekten
PostPosted: Wed Oct 06, 2010 2:19 am 
Newbie

Joined: Wed Oct 06, 2010 2:14 am
Posts: 1
Hallo,

Ich habe ein Objekt EmailGroupDTO, dieses besitzt es Set von EmailGroupMember.
Das Hibernate-Mapping sieht folgendermaßen aus:
<class name="EmailGroupDTO" table="S83RP04D120" mutable="true" lazy="false">
<id name="groupId" column="GROUP_ID" type="long" />
<property name="groupName" column="GROUP_NAME" type="string" />
<property name="groupOwner" column="OWNER" type="string"/>
<set name="groupMembers" table="S83RP04D121" inverse="true" cascade="all" lazy="false">
<key column="GROUP_ID"/>
<one-to-many class="EmailGroupMember" />
</set>
</class>

Die Methode zum Speichern sieht folgendermaßen aus:

public EmailGroupDTO storeEmailGroup(EmailGroupDTO emailGroup) throws PersistenceException {
Session session = HibernateUtil.getInstance().getCurrentSession();

Long groupId;
if (emailGroup.getGroupId() != null) {
groupId = emailGroup.getGroupId();
} else {
groupId = createPrimaryKey(KEY_RANGE);
emailGroup.setGroupId(groupId);
}

// set group id for all members
for(EmailGroupMember member : emailGroup.getGroupMembers()) {
member.setGroupId(groupId);
}

try {
session.saveOrUpdate(emailGroup);
} catch (HibernateException he) {

}

return emailGroup;
}

Das Anlegen neuer E-Mail-Gruppen funktioniert, auch das Hinzufügen von neuen Mitgliedern funktioniert. Lösche ich aber bestehende Mitglieder aus einer E-Mail-Gruppe, so werden diese nicht aus der Datenbank gelöscht.

Was muss ich ändern?


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.