Hello everybody!
I'm new to this forum, and I hope this post fits the usual formatting requirements and so on. pls tell me if not.
My Problem concerns an outer-join fetch I want to achieve. I have an entity User, that holds a collection of UserAttributes. The UserAttributes itself have a relationship to Attributes. Attributes are a kind of type that an UserAttribute can have. UserAttributes are stored in the user_attributes (n:m) table. The Attributes are stored into the attributes table. Now I want to retrieve empty attributes for each attribute in the UserAttributes table, even if there is no corresponding entry in the user_attributes (n:m) table.
Somehow I can't get NHibernate to use outerjoin fetching. It always ends up in an inner join fetch.
I hope someone can help
Thx in advance & kind regards
Hibernate version:
1.2.0.4
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PersistenceLayer.Entities.User.User, PersistenceLayer" table="users">
<id name="Id" column="userId" type="String">
<generator class="uuid.hex" />
</id>
<property name="Username" column="username" type="String" length="20"/>
<property name="Password" column="password" type="String" length="20"/>
<property name="IsLocked" column="isLocked" type="Boolean" />
<property name="FailedLogins" column="failedLogins" type="Int16" />
<set name="Attributes" table="user_attributes" lazy="false" cascade="all" outer-join="true">
<key column="userId" />
<composite-element class="PersistenceLayer.Entities.EntityAttribute, PersistenceLayer">
<property name="Value" column="value" />
<many-to-one name="Attribute" column="attributeId" class="PersistenceLayer.Entities.User.UserAttribute, PersistenceLayer" outer-join="true" fetch="join" not-null="true" lazy="false" />
</composite-element>
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PersistenceLayer.Entities.User.UserAttribute, PersistenceLayer" table="userAttributes">
<id name="Id" column="attributeId" type="String">
<generator class="uuid.hex" />
</id>
<property name="Name" column="attributeName" type="String" not-null="true" />
<property name="OrderId" column="orderId" type="Int16" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():extends Springs' NHibernateDaoSupport
Name and version of the database you are using:SQL Server 2005
The generated SQL (show_sql=true):Code:
2008-01-16 09:02:57,881 [8] DEBUG NHibernate.SQL [(null)] - SELECT attributes0_.userId as userId__1_, attributes0_.value as value1_, attributes0_.attr
ibuteId as attribut3_1_, userattrib1_.attributeId as attribut1_3_0_, userattrib1_.attributeName as attribut2_3_0_, userattrib1_.orderId as orderId3_0_
FROM user_attributes attributes0_ inner join userAttributes userattrib1_ on attributes0_.attributeId=userattrib1_.attributeId WHERE attributes0_.user
Id=@p0; @p0 = '1'
Debug level Hibernate log excerpt:DEBUG
[/code]