-->
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.  [ 7 posts ] 
Author Message
 Post subject: Collection question.
PostPosted: Thu Aug 28, 2003 6:49 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
HI alls.

I've got 3 tables.

Company (id, name)
Property(id, name, ref_id, lang_id)
Language(id, name)

in Company class;
public class Company {
private List properties;

/**
* @hibernate.bag inverse="false"
* table="multilanguage_property"
* lazy="false"
* cascade="all"
* inverse="true"
* where="disc like 'comp'"
* @hibernate.collection-key column="ref_id"
* @hibernate.collection-one-to-many
* class="com.clearview.feedback.db.language.MultiLanguageProperty"
* @return
*/
public List getProperties() {
return properties;
}

public void setProperties(List properties) {
this.properties = properties;
}
}

when i try to execute such code

Company company = new Company();
ArrayList prop = new ArrayList();
MultiLanguageProperty nameProperty =
new MultiLanguageProperty("kuku",
null, Language.getLanguage("en", session));
prop.add(nameProperty);
company.setProperties(prop);
session.saveOrUpdate(company); <----- here is exception

I get an exception: net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found).

Because Hibernate is trying to execute SQL UPDATE but not SQL INSERT.

If i try to add to property list more than one Property, i get such exception:
net.sf.hibernate.HibernateException: Another object was associated with this id (the object with the given id was already loaded): [com.clearview.feedback.db.language.MultiLanguageProperty#0]

Company company = new Company();
ArrayList prop = new ArrayList();
MultiLanguageProperty nameProperty =
new MultiLanguageProperty("kuku",
null, Language.getLanguage("en", session));
MultiLanguageProperty nameProperty =
new MultiLanguageProperty("kuku",
null, Language.getLanguage("fr", session));
prop.add(nameProperty);
company.setProperties(prop);
session.saveOrUpdate(company); <---- here is exception

How can i solve this problem. Thank's


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 3:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a FAQ!


set unsaved-value="0"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 3:15 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
This is a FAQ!


set unsaved-value="0"


It didn't help. But when i changed "long id" to "Long id" and set unsaved-value="null", everything is ok.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 5:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I am *quite* certain that unsaved-value="0" would work, if you put it everywhere that is needed ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 5:12 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
I am *quite* certain that unsaved-value="0" would work, if you put it everywhere that is needed ;)

Maybe it should work but in my case it doesn't work.
I just change long -> Long and unsaved-value="0" -> unsaved-value="null" and it works.
Maybe i have crooked hands or maybe there's a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 5:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is no bug. Most likely you are not *really* using the mapping you think you are using.


Trust Me. This is VERY well-unit-tested. It can't possibly break. It is a mistake at your end.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 6:35 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:44 pm
Posts: 20
gavin is right.it's not bug in hibernate.I did the same mistake by declaring as primitive type and my unsaved value = null and when i called save() it was sending wrong sql,after changing to 0 everything was working fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.