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.  [ 5 posts ] 
Author Message
 Post subject: OneToOne sql performance/results issue
PostPosted: Mon Oct 02, 2006 3:04 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
I have an AppUser object with a default workschedule as below:

Code:
[NHMA.OneToOne( 0, Name = "DefaultWorkSchedule", ClassType = typeof( DefaultWorkSchedule ), OuterJoin = OuterJoinStrategy.True, PropertyRef = "AppUser" )]
        public virtual DefaultWorkSchedule DefaultWorkSchedule
        {
            get { return defaultWorkSchedule; }
            set { defaultWorkSchedule = value; }
        }


Here's the relevant class code from default workschedule:

Code:
[Serializable]
    [Subclass(0, NameType = typeof(DefaultWorkSchedule), DiscriminatorValueEnumFormat = "d", DiscriminatorValueObject = ScheduleType.Default, ExtendsType = typeof(WorkSchedule))]


    public class DefaultWorkSchedule : WorkSchedule
//etc..


And here's the base class work schedule info:

Code:
[Serializable]
    [Class(0, NameType = typeof(WorkSchedule), Table = "WorkSched", DiscriminatorValue = "99")]
    [AttributeIdentifier("ID.Column", Value = "WorkSchedID")]
    [AttributeIdentifier("StartDateTime.Column", Value = "StartDateTime")]
    [AttributeIdentifier("EndDateTime.Column", Value = "EndDateTime")]
//etc.


Ok, if I leave off this: OuterJoin = OuterJoinStrategy.True, it will try to run 5000 individual select statements when loading a grid of AppUsers. If add it, the sql is wrong. It generates this sql:

Code:
SELECT this_.AppUserID as AppUserID43_1_, this_.LoginName as LoginName43_1_, this_.FirstName as FirstName43_1_,
this_.LastName as LastName43_1_, this_.FullName as FullName43_1_, this_.ActiveFlag as ActiveFlag43_1_,
this_.UID as UID43_1_, this_.CUID as CUID43_1_, this_.HireDate as HireDate43_1_, this_.SeniorityRank as Seniori10_43_1_,
this_.SupervisorID as Supervi11_43_1_, this_.AgentID as AgentID43_1_, this_.PhoneNum as PhoneNum43_1_,
this_.iPager as iPager43_1_, this_.FaxNum as FaxNum43_1_, this_.EMailAddress as EMailAd16_43_1_, this_.WfaID as WfaID43_1_,
this_.SalesCode as SalesCode43_1_, this_.LocationID as LocationID43_1_, defaultwor2_.WorkSchedID as WorkSche1_16_0_,
defaultwor2_.AppUserID as AppUserID16_0_, defaultwor2_.StartDateTime as StartDat3_16_0_,
defaultwor2_.EndDateTime as EndDateT4_16_0_ FROM DaTrashCan.clairvoyant.AppUser this_
left outer join DaTrashCan.clairvoyant.WorkSched defaultwor2_ on this_.AppUserID=defaultwor2_.AppUserID
WHERE this_.ActiveFlag = 1 ORDER BY this_.FullName asc


When it should generate this:

Code:
SELECT this_.AppUserID as AppUserID43_1_, this_.LoginName as LoginName43_1_, this_.FirstName as FirstName43_1_,
this_.LastName as LastName43_1_, this_.FullName as FullName43_1_, this_.ActiveFlag as ActiveFlag43_1_,
this_.UID as UID43_1_, this_.CUID as CUID43_1_, this_.HireDate as HireDate43_1_, this_.SeniorityRank as Seniori10_43_1_,
this_.SupervisorID as Supervi11_43_1_, this_.AgentID as AgentID43_1_, this_.PhoneNum as PhoneNum43_1_,
this_.iPager as iPager43_1_, this_.FaxNum as FaxNum43_1_, this_.EMailAddress as EMailAd16_43_1_, this_.WfaID as WfaID43_1_,
this_.SalesCode as SalesCode43_1_, this_.LocationID as LocationID43_1_, defaultwor2_.WorkSchedID as WorkSche1_16_0_,
defaultwor2_.AppUserID as AppUserID16_0_, defaultwor2_.StartDateTime as StartDat3_16_0_,
defaultwor2_.EndDateTime as EndDateT4_16_0_ FROM DaTrashCan.clairvoyant.AppUser this_
left outer join DaTrashCan.clairvoyant.WorkSched defaultwor2_ on this_.AppUserID=defaultwor2_.AppUserID and defaultwor2_.DefaultFlag = 1
WHERE this_.ActiveFlag = 1 ORDER BY this_.FullName asc


Am I missing something in the mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 9:19 am 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
It looks like the discriminator isn't being used when the OuterJoin strategy is True.

Looks like a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 3:10 pm 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
I've been able to reproduce this problem.

I have class A with sub classes A1 and A2. When I use sub-selects the discriminator is properly added to the where clause of the generated sql. However, when I use the OuterJoin.true the discriminator is not included in the left outer join or the where clause.

My question, does NHibernate support the use of Inhertitance/Discriminators with the OuterJoins? Or is one forced into using Sub-Selects with Inheritance?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 1:27 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Report this to JIRA please, I will investigate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 8:45 am 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
JIRA submitted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.