-->
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: Outerjoin fetch with composite element and many-to-one
PostPosted: Wed Jan 16, 2008 4:43 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
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]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 11:55 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Your formatting is fine, but your naming is very confusing. I'm having a hard time understanding what end result you are looking for here, and whether it is reasonable or not. You may have been better off with a naming schema like "UserAttribute" for the association (n:m) class, and "UserAttributeType" or "UserAttributeCategory" or something, because as it stands I can't tell what any given usage of "attribute" refers to. The fact that you have tables in the same project named "user_attribute" and "userAttribute" is a signal that something is wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 2:34 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
marcal,

I'm with you that the UserAttributes seems to be the Attributes of Users in the first sight and that it would be better to call them UserAttributeTypes. user_attributes should be user_userAttributes, but by convention every table that contains an underscore is a mapping table - at least in this project ;)

But I think you got the idea right. The corequestion was why nhibernate always uses innerjoins instead of outerjoins. I don't think nhibernate does that because of confusing namingconventions ;-)

regards


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.