-->
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: Issues mapping legacy data
PostPosted: Wed Feb 25, 2004 4:21 pm 
Newbie

Joined: Wed Feb 25, 2004 3:37 pm
Posts: 1
I have a legacy system and I'm trying to use Hibernate as our data access method for a new project that will coexist with the other legacy applications.
Assume I have a class: (ignoring the contrived example...)

Code:
class Person {
    Long id;
    Person brother;
// other stuff...
}


Assume the table is:

Code:
create table person (
    id number primary key,
    brother number
);


In my mappings, I've set up a many-to-one relationship. (It doesn't seem right, but it does seem to work...) i.e.:

Code:
<class name="Person" table="person">
    <id name="id" type="java.lang.Long"/>
    <many-to-one name="brother" class="Person">
        <column name="brother"/>
    </many-to-one>
</class>

(Please let me know if there's a better way to create this mapping...)

Here's my problem: If a "person" has no "brother", the "person.brother" column should be NULL. However, because of some coding errors in other programs, sometimes the brother field is "0" (zero). (There's no foreign key constraint on the field, so the database allows this. Since our legacy code did these lookups manually, we simply worked around the problem by only doing the lookup if the field > 0.) Understandably, when I try to load this object in Hibernate, it complains that it cannot find a row where person.id = 0.

Assuming that "fixing" the problem in the database is not an option, I'm trying to find a work-around that will allow us to use Hibernate.

(I tried creating an Interceptor that would identify this condition. In the Interceptor, I tested if person.brother was not null, and person.brother.id == 0, then set person.brother = null. This didn't work because somewhere prior to the calling of the Interceptor Hibernate must have stored a reference to "Person#0", and still threw an exception when attempting to resolve the reference.)

Any assistance would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 6:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try to search the forum, I discussed that a long time ago on a workaround.
Let me know.

_________________
Emmanuel


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.