-->
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: Mapping with dirty data
PostPosted: Tue Apr 08, 2008 8:19 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
I am using Hibernate 3.2.6, with annotations 3.3.0
Mysql 5.0

I am working with a legacy database, and am trying to convert the jdbc code to hibernate.

The data is somewhat dirty, specifically

I have a database where one table column references another by the primary key

The column should have been nullable, but instead when no matching row was found the programmer inserted either 0 or -1.

So I have the following mapping in my model file

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "media_id", nullable = true, updatable=false, insertable=false)
private Media media;


and media_id is either a reference to the media table, or is 0 or -1, if no match is found

So I would like hibernate to give null for media, if media_id = 0 or -1


How would I do this?

Thanks


Top
 Profile  
 
 Post subject: Re: Mapping with dirty data
PostPosted: Tue Apr 08, 2008 9:14 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
See if @NotFound(action=NotFoundAction.IGNORE) helps.




Farzad-


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.