-->
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.  [ 2 posts ] 
Author Message
 Post subject: newbie with a common problem
PostPosted: Fri Apr 04, 2008 7:57 pm 
Newbie

Joined: Fri Apr 04, 2008 7:43 pm
Posts: 2
Looking at the "Common Problems" section I see this:
Quote:
I'm using assigned identifiers, or a <composite-id> with cascades or saveOrUpdate() and Hibernate throws a StaleObjectState exception or SQL insert, update or delete failed (row not found).

Assigned identifiers, including composite identifiers, can't be used to distinguish newly instantiated instances from instances saved or loaded in a previous session. You will need to provide some other way for Hibernate to distinguish.

My problem is that I have a legacy database that's populated with data. I'm tryingb to migrate some nasty C++ code to Java with Hibernate. The structure looks something like this:

Class FOO {
int fooId
String fooName
Set<BAR> bar
}

Class BAR {
int fooId
int non_unique_value
}

I've created a primary key (fooId, non_unique_value) and by using a composite-id I can load the data. However I can't save back- I get "SQL insert, update or delete failed (row not found)."

Not clear what my options are here. I suppose I could add another column to the table, but I'm not sure howthat would affect the legacy code, or how I'd populate it with unique values - I'm not a DBA. Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 7:58 am 
Newbie

Joined: Fri Apr 04, 2008 7:43 pm
Posts: 2
Well thanks for nothing, board. I eventually figured out a solution, which was to take a copy of the FOO:bar set and null out the original. That way I could save FOO. I could then iterate through FOO:bar and save each element in turn.

Seems a long-winded way to do it, but it works.


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