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