-->
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.  [ 3 posts ] 
Author Message
 Post subject: Legacy system without referential integrity
PostPosted: Tue May 20, 2008 3:25 am 
Beginner
Beginner

Joined: Mon Apr 02, 2007 8:08 am
Posts: 24
I have a legacy database which doesn't keep referential integrity: there are some columns which are "almost" a FK: they are supposed to reference another table row, but it's not always true (sometimes it has a value but referenced row doesn't exist).

In this case Hibernate fails (org.hibernate.ObjectNotFoundException: No row with the given identifier exists). Is there any way I can handle this? I could map the column as a simple property instead of a relationship, but I want to be able to go through the relationship when it's ok.

_________________
--
<a href="http://ideasse.blogspot.com/">Ideas + Software Engineering</a> (English)
<a href="http://iiso.blogspot.com/">Ideas + IngenierĂ­a del Software</a> (Spanish)


Top
 Profile  
 
 Post subject: Re: Legacy system without referential integrity
PostPosted: Tue May 20, 2008 7:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
juanignaciosl wrote:
I have a legacy database which doesn't keep referential integrity: there are some columns which are "almost" a FK: they are supposed to reference another table row, but it's not always true (sometimes it has a value but referenced row doesn't exist).


Couldn't you 'clean up' the data first? What does it mean then if a column has a value AND the referenced row does not exist?

That aside - Hibernate allows you to customize the SQL used for loading entities and collections. See for example http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querysql-load. The book Java Persistence with Hibernate covers this topic in more detail and gives a lot of other valuable tips when working with legacy databases.

Personally, I would try to investigate first the option of a database cleanup or maybe even schema modification.

Good luck :)

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 20, 2008 7:15 am 
Beginner
Beginner

Joined: Mon Apr 02, 2007 8:08 am
Posts: 24
I agree you, correcting the data IS the RIGHT option, but I'm afraid it's not possible. This is a legal issue, dealing with application testing, sensible information... hard to explain...

I'll try the custom SQL you suggest. Thanks!

_________________
--
<a href="http://ideasse.blogspot.com/">Ideas + Software Engineering</a> (English)
<a href="http://iiso.blogspot.com/">Ideas + IngenierĂ­a del Software</a> (Spanish)


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