473,385 Members | 1,655 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,385 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 4733
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.