-->
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: composite-id with nullable columns?
PostPosted: Mon Jan 08, 2007 1:47 pm 
Newbie

Joined: Mon Jan 08, 2007 1:17 pm
Posts: 2
I'm working with a flattened database view, where it doesn't have a good primary key design. It looks like this:
column A (not null)
column B (not null)
column C (nullable)

Where sometimes column C is used to identify between rows, and sometimes it's null, and it is assumed A and B are enough to uniquely identify a row.

e.g. You could have data like this:
A B C
1 1 1
1 1 2
1 2 null

The problem is, I'm not sure how to model my mapping.
If I model it so that column C is part of the composite-id, then that third row I get back in a query is completely null. e.g. The list.size() is 3, but only two of the elements are populated.
But if I just treat column C as a property of Foo and not part of FooId, then I only get two rows back in a query, and the data returned is a duplicate of row 1.

Am I missing something basic here, or is this type of mapping not currently allowed? TIA.

Here's what my mapping looks like:
Code:
<hibernate-mapping>
  <class name="Foo" table="foo">
    <composite-id name="id" class="FooId">
      <key-property name="a" type="java.lang.String" column="a"/>
      <key-property name="b" type="java.lang.String" column="b"/>
      <key-property name="c" type="java.lang.String" column="c"/>
    </composite-id>
    <property name="d" type="java.lang.String" column="d"/>
    <property name="e" type="java.lang.String" column="e"/>
  </class>
</hibernate-mapping>


public class Foo implements Serializable {
    private FooId;
    private String d;
    private String e;
}


public class FooId implements Serializable {
    private String a;
    private String b;
    private String c;
   

    // implemented equals and hashcode, allowing for c to be null
   
}


Top
 Profile  
 
 Post subject: Re: composite-id with nullable columns?
PostPosted: Mon Jan 08, 2007 3:24 pm 
Newbie

Joined: Mon Oct 17, 2005 2:55 pm
Posts: 5
Location: Toronto, Canada
Hopefully CompositeUserType will give you a good and stable solution.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 08, 2007 3:45 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I don't think hibernate will elt you have a null member of a composite key. You could try a CustomUserType like the above guy said and change it to something for use in hibernate but I'm not sure how early hibernate checks for good data.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.