-->
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.  [ 12 posts ] 
Author Message
 Post subject: saveOrUpdate always inserts
PostPosted: Wed Feb 11, 2004 12:31 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
Is there anything I need to do to get saveOrUpdate to work.

All the fields other then the id are identical but when i save it to the session keeps inserting.


Any ideas?

Cheers Mark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Your unsaved-value mapping is wrong. http://www.hibernate.org/hib_docs/reference/html/manipulating-data.html#manipulating-data-s8


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:34 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Check your unsaved-value in your mapping. It is probably missing or wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:44 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
Okay here;s some context

AddressForm userInputAddres = (AddressForm) form;
List addressList = customer.getAddresses();

Address address = new Address();

BeanUtils.copyProperties(address, userInputAddress);

if(!addressList.contains(address)) {
AddressUtil.save(address);
}

..then in my Util class

session.saveOrUpdate(address);

So when I haven't an id does hibernate have no means of comparing all the other fields to work out whether to save or update .. after all the method is called saveOrUpdate

Cheers MArk


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:48 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Read the javadoc for saveOrUpdate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 1:31 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
Done that.. In fact documentation reading is pretty much all i've been doing thanks for the wisdom..

Looks like I need to have a find/query rather than instantiating the object

Something like

Address address = AddressUtil.getAddressByEveryFuckingFieldByNotId(str, str, str);

Thanks for the RTFM.. Next time RMFQ..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
First you talk about saveOrUpdate, now you suddenly talk about querying. What are you actually trying to do? Probably learn to formulate your questions properly before being rude.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 2:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mark.lowe wrote:
So when I haven't an id does hibernate have no means of comparing all the other fields to work out whether to save or update ..

Why 2 objects having all but 1 attibutes equal should be considered as the same ?

id (or composite-id) is the heart of every ORM tools.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 2:59 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
thanks emmanuel

I had a feeling composite_id might be the puppy.. I've hacked it for now just doing a query with the other fields, I'll look into making things more elegant later.

Cheers you've given me the answer I wanted.

RE a couple of messages ago: Sure my question could do with sharpening, but then again its not the worst question I've seen. I'm talking about saveOrUpdate and then querying as if I don't query before saveOrUpdating it create an insert. I just get peeved with jokers who constantly give RTFM responses between spanking their monkies or lurking in public lavatories. My short commings were obvious emmanuel saw this and pointed me in the right direction, my thanks to him.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 8:54 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You know we're peeved with people not helping themselves and asking to be driven step after step. Rude content is not excusable from a people asking for help for free.

A quote from the ask for help page I 100% agree.

    Don't insult Hibernate or the people who worked hard to develop it. You want an answer to your problem, right? Insulting people is a really bad way to get it. People will deliberately not answer your question because they would prefer that you just go away; they don't want to encourage you to come back and insult them again.

    You are asking a favor. No-one has any responsibility to help you. You have not paid any money to use Hibernate. Nevertheless, the level of "free" support provided is far beyond what you could expect from most commercial software vendors. Even though the support is provided for free, it is certainly not free to the person providing it. They are taking time away from their own busy life to help you. Most of the time they take great pleasure from this - but only when they are treated with respect.


I'm a customer of several commercial supports, they do not help me as much as I can see on this forum.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 9:08 am 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
Sure thanks for that..

I didn''t expect anything, i just think my question wasn't that bad and where i was at was probably a classic. You saw it. I just have problems with smart alecs post read the manual when folks have been. sure sometimes its obvious that folks haven't and expect others to do their work but thats quite a different thing.

Better not responding at all than just mindlessly posting read the manual. Again I reiterate the shortcommings in my question were related to the broader issue of my knoweldge of OM in general.

now i'm hunting trhough trying to find as much as i can on composite id's and such like, pointing me to saveOrUpdate documentation had certain implicitures that I took exception to, for one that hadn't had my nose in the docs before that. I merely mirrored the commicative act that was directed toward me.

Cheers Mark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:50 pm 
Newbie

Joined: Wed Nov 30, 2005 4:40 pm
Posts: 14
Location: St. Louis MO.
I have a similar question. Since the "id" is not relevant to the business object, but rather simply a database PK, what is the best way to attach an existing db row to a Java object? Session.load(SomeClass, new Long(150)) works okay if I happen to know the row I need is PK=150! Of course I would not know the auto-numbered value! I must be missing something here.

Thanks,
Scott


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