-->
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: Composite key with nullable columns
PostPosted: Sun Feb 08, 2009 5:57 pm 
Newbie

Joined: Sun Feb 08, 2009 5:51 pm
Posts: 1
I have a situation where I have a composite key for a table in which one of the columns may be nullable and must be included in the key to insure uniqueness. From what I can tell, this is not supported by Hibernate. This is a legacy database and I am not able to make any changes top the schema.

My mapping looks something like this:

Code:
<hibernate-mapping>
  <class name="UserDefField" table="USER_DEF_FIELDS" lazy="false">
    <composite-id name="udfId" class="UserDefFieldId" >
        <key-property name="programId" type="string" column="PROGRAM_ID"/>
        <key-property name="docid" type="string" column="DOC_ID"/>
        <key-property name="nullableCol" type="integer" column="NULLABLE_COL"/>
    </composite-id>

    <property name="dateVal" type="timestamp" column="DATE_VAL"/>
  </class>
</hibernate-mapping>


I can tell based on the value of DOC_ID whether or not the nullableCol will be null.

Is there a way that I can map this table to two classes that have different composite keys based on the value of DOC_ID?

Something like class UdfWithNull which is keyed by only programId and docId is used for rows with docId = "ABC" while class UdfWithoutNull is keyed by programId, docId, and nullableCol for rows with docId <> "ABC"?

Any help would be appreciated.[quote][/quote]

_________________
Thanks,
John


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 7:49 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
May be you can create two views, one with nullable column and one without it.

_________________
Regards,
Litty Preeth


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.