473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Hibernate saveOrUpdate Objects with Lists

42
I'm wondering how to do saveOrUpdate properly for Objects that contain lists of other objects. The way it now does it for me, is that saveOrUpdate works fine with object itself, but it adds new entries for the object's list even though those entries already exist. In other words, it is duplicating data unnecessary.

Could someone help or show me how such a mapping is done? I have the hibernate mapping files, but do not have access to them from this computer. I can post them later if they are deemed necessary.

I'm using "assigned" for parent object's generator-class.
Feb 13 '10 #1
1 4729
Humakt
42
Help anyone?

Here are sample of mapping files.

The main object:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  3. <!-- Generated 13.11.2009 9:13:54 by Hibernate Tools 3.2.1.GA -->
  4. <hibernate-mapping>
  5.   <class catalog="ohtu_s09_r2" name="lukki.pavut.Toteutus" table="Toteutus">
  6.     <id name="totid" type="string">
  7.       <column name="totid"/>
  8.       <generator class="assigned"/>
  9.     </id>
  10.     <property name="alkuper" type="date">
  11.       <column name="alkuper"/>
  12.     </property>
  13.     <property name="loppuper" type="date">
  14.       <column name="loppuper"/>
  15.     </property>
  16.     <property name="kurssi" type="string"/>
  17.     <list cascade="all" name="opettajat">
  18.       <key column="totid" not-null="true"/>
  19.       <index column="idx"/>
  20.       <one-to-many class="lukki.pavut.Henkilot"/>
  21.     </list>
  22.     <list cascade="all" name="ryhmat">
  23.       <key column="totid"/>
  24.       <index column="idx"/>
  25.       <one-to-many class="lukki.pavut.Ryhmat"/>
  26.     </list>
  27.     <list cascade="all" name="totajat">
  28.       <key column="totid"/>
  29.       <index column="idx"/>
  30.       <one-to-many class="lukki.pavut.Toteutuksenajat"/>
  31.     </list>
  32.     <list cascade="all" name="kevytkotisivut">
  33.       <key column="totid"/>
  34.       <index column="idx"/>
  35.       <one-to-many class="lukki.pavut.KevytKotiSivu"/>
  36.     </list>
  37.     <list cascade="all" name="suunnitelmat">
  38.       <key column="totid"/>
  39.       <index column="idx"/>
  40.       <one-to-many class="lukki.pavut.Suunnitelma"/>
  41.     </list>
  42.   </class>
  43. </hibernate-mapping>
One of the mappings for list object:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  3. <!-- Generated 13.11.2009 9:13:54 by Hibernate Tools 3.2.1.GA -->
  4. <hibernate-mapping>
  5.   <class catalog="ohtu_s09_r2" name="lukki.pavut.Toteutuksenajat" table="Toteutuksenajat">
  6.     <id name="id" type="java.lang.Integer">
  7.       <column name="id"/>
  8.       <generator class="identity"/>
  9.     </id>
  10.     <property name="alkua" type="java.lang.Integer">
  11.       <column name="alkua"/>
  12.     </property>
  13.     <property name="kesto" type="java.lang.Integer">
  14.       <column name="kesto"/>
  15.     </property>
  16.     <property name="luokka" type="string">
  17.       <column length="65535" name="luokka"/>
  18.     </property>
  19.     <property name="paiva" type="java.lang.Integer">
  20.       <column name="paiva"/>
  21.     </property>
  22.   </class>
  23. </hibernate-mapping>
Feb 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Keith Simeon | last post by:
Hello all, I've recently started playing with Hibernate, and have a question regarding many-to-many relationships using a join or cross table (I've also heard these referred to as a transition...
1
by: AG | last post by:
After an upgrade to WebSphere/JDK environment (6.1/1.5) I am getting following error on Hibernate objects. Unfortunately, I was not able to find any info on ibm's web site about SQLCODE 4700. ...
1
by: chandukandula | last post by:
Hi Already my application in Struts using JDBC.At present my application is implemented in Struts with hibernate So i am not changing the SQL queries converting to the like this String...
1
by: Sergiu DUDNIC | last post by:
Hello, I would like to know, if there are a analog for the Hibernate 's Java approach in the .NET Framework. As I understand Java's hibernate allows to conserve, and use the programmed...
6
rsrinivasan
by: rsrinivasan | last post by:
Hi all, I am using Hibernate framework in my project. This is my configuration in my "hibernate.cfg.xml" file. <property name="hibernate.c3p0.max_size">25</property> <property...
3
by: altafur | last post by:
hi, i am using java with hibernate . i want to run a hibernate order by query thru java. i have written the query in hibernate.hbm.xml file. the query is as follows: query: SELECT distinct...
0
by: neuraljay | last post by:
hi everyone. I am trying to build a jsp using webwork, hibernate and mysql. And right now I am doing its unit testing. Everytime I run the test I am getting this error: Error JDBC exception on...
1
by: ashi1290 | last post by:
I am getting this error..... Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:120)...
1
Paks
by: Paks | last post by:
Hi there, I'm developing a web project based game and have run into a problem and gotten confused by the annotations in the Hibernate framework. I'm trying to have both the relation and child...
2
oll3i
by: oll3i | last post by:
I have hibernate plugin for eclipse (org.hibernate.eclipse_3.2.3.GA) it came together with eclipse europa , but when i do the import to use hibernate import org.hibernate.Session; import...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.