-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping collection with composite keys that can be nullable
PostPosted: Thu Mar 15, 2012 10:41 am 
Newbie

Joined: Thu Mar 15, 2012 9:52 am
Posts: 1
Hi,

my Database-Tables look like this:
Code:
CustomerSales
-----------------
CustomerId (int, not null)
SalesOrgId (int, not null)
Some other columns...

The primary key of the table consists of the columns CustomerId and SalesOrgId.


Code:
CustomerAttributes
-------------------
CustomerAttributeId (int, not null)
CustomerId (int, not null)
SalesOrgId (int, null)
AttributeName (string, not null)
AttributeValue (string, not null)

The primary key of the table consists of the column CustomerAttributeId.


If the column SalesOrgId is null for a row in table CustomerAttributes, this means that the attribute belongs to all CustomerSales with the given CustomerId and it doesn't matter which SalesOrgId they have.

Example:

Code:
CustomerSales:
CustomerId, SalesOrgId,...
1234, 1,...
1234, 2,...
2345, 1,...

CustomerAttributes:
AttributeId, CustomerId, SalesOrgId, AttributeName, AttributeValue
1, 1234, 1, PaymentTerm, ZD12
2, 1234, 2, PaymentTerm, ZD03
3, 1234, null, EyeColor, Blue


Now I want to map a list of CustomerAttributes that belong to the customer. That means attributes with the same CustomerId and the same SalesOrgId and attributes with the same CustomerId and SalesOrgId=null.

My CustomerSales is mapped like this:

Code:
  <class name="CustomerSales" table="CustomerSales" mutable="false">

    <composite-id>
      <key-property name="CustomerId" column="CustomerId" type="int"/>
      <key-property name="SalesOrgId" column="SalesOrgId" type="int"/>
    </composite-id>

    <property name="..."/>
   
    <bag name="CustomerAttributeCollection" lazy="true" inverse="true">
      ???
      <one-to-many class="CustomerAttribute"/>
    </bag>
  </class>


A possible solution would also be, if it is only mapped on the CustomerId and the SalesOrgId is checked in the getter of my CustomerAttributeCollection property.
I got this to work without lazy loading. But with lazy loading, I always get a "session is closed" exception, although the session is still open!

Thanks for your answers in advance.

Regards, Franzi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.