-->
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: ManytoMany SaveOrUpdate speichert nur letzten Eintrag (Java)
PostPosted: Mon Sep 27, 2010 1:28 pm 
Newbie

Joined: Mon Sep 27, 2010 1:20 pm
Posts: 2
Hallo in die Runde,

ich habe eine "many-to-many" mapping das folgender maßen aussieht:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="models.Page" table="Page">
    <id column="id" name="Id">
      <generator class="increment"/>
    </id>
    <property column="Name" name="Name"/>
    <many-to-one class="models.Layout" column="layout_id" name="Layout"/>
    <set name="Content" table="Pagecontent_content">
      <key column="page_id"/>
      <many-to-many class="models.Content" column="content_id"/>
    </set>
    <set name="Title" table="Pagetitle_content">
      <key column="page_id"/>
      <many-to-many class="models.Content" column="content_id"/>
    </set>
    <set name="SubMenu" table="Page_submenuitem">
      <key column="page_id"/>
      <many-to-many class="models.SubMenuItem" column="submenuitem_id" not-found="ignore"/>
    </set>
  </class>
</hibernate-mapping>


Ich möchte ein Object speichern welches jeweils zwei "Contents" in "Title" und in "Content" hat. Das funktioniert leider nur halb. Es läuft sauber durch, aber gespeichert sind am Ende nur ein Eintrag aus jeder Liste. Sind zwei oder mehr Einträge in der Liste, werden diese in der entsprechenden Content Tabelle gespeichert, aber leider nicht zur "Page" relation hinzugefügt.

Speichern tue ich folgender mßen.

Code:
            fSessionFactory = new Configuration().configure().buildSessionFactory();
            fSession = fSessionFactory.openSession();
            Transaction tx = fSession.beginTransaction();

            fSession.saveOrUpdate(page.Layout);

            for(int i = 0; page.Content != null && i < page.Content.size(); i++) {
                fSession.saveOrUpdate(page.Content.get(i));
            }

            for(int i = 0; page.Title != null && i < page.Title.size(); i++) {
                fSession.saveOrUpdate(page.Title.get(i));
            }

            for(int i = 0; page.SubMenu != null && i < page.SubMenu.size(); i++) {
                for(int j = 0; page.SubMenu.get(i).Content != null && j < page.SubMenu.get(i).Content.size(); j++) {
                    fSession.saveOrUpdate(page.SubMenu.get(i).Content.get(j));
                }
                fSession.saveOrUpdate(page.SubMenu.get(i));
            }

            fSession.saveOrUpdate(page);

            tx.commit();


Kann mir jemand helfen? Weiss jemand wo das Problem liegt?


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.