-->
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: null value for property for some values of the DB column
PostPosted: Sun Mar 29, 2009 9:14 am 
Newbie

Joined: Tue Mar 03, 2009 9:32 am
Posts: 7
Hi,

I have an entity which has another entity associated as a oneToOne.
I want to return null for some specific values of the connecting column (e.g: when the column value is -1). how can I do that?


Many thanks, Uri.

_________________
Regards,
Uri Bar


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 30, 2009 8:25 am 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
Hey Uri,

Why not just allow nulls in the column?

I was trying to find an answer to your same question. Then I realized there was no real reason why I wanted to do it. I had always just kept nulls out of number columns because it means writing less code for data access. However, when using Hibernate, Hibernate handles all of that for you. In hibernate world having a null in a numeric column is no problem (as far as I can tell).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 30, 2009 8:38 am 
Newbie

Joined: Tue Mar 03, 2009 9:32 am
Posts: 7
Hi sowelie,

Thank you for your reply. The problem is I am working with a legacy DB.
The column that serves as the join-column in my table is receiving normal values (id's for the refrenced table) and also get the -99 value which basically says there is a different type of relation.

The main problem is that this is a legacy DB and I must support the already existing features/behaviors.

My solution was to write an xml mapping, because JPA/hibernate annotations currently don't support formula the way xmls do.

I defined the problematic property as such:
<one-to-one name="problematicProperty" class="com.blabla.someEntity" access="field">
<formula>case when someEntity_id=-99 then null else someEntity_id end</formula>
</one-to-one>

_________________
Regards,
Uri Bar


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.