-->
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: Issue with join configuration
PostPosted: Mon Dec 03, 2007 4:03 pm 
Newbie

Joined: Mon Dec 03, 2007 3:53 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.0.0.1001

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Panther.Schedule"
assembly="panther.sched.nhibernate">

<class name="Panther.Scheduling.ScheduledQuery, panther.sched.nhibernate"
table="MessageScheduleRecurrenceQuery" >

<id name="ScheduleRecurrenceId" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"
column="ScheduleRecurrenceID"
type="Int32">
<generator class="assigned"/>
</id>

<property name="ScheduleRecurrenceId" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"/>

<property name="SendOnEmpty" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"/>
<property name="SendOnError" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"/>

<set name="Parameters" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate">
<key property-ref="ScheduleRecurrenceId"/>
<one-to-many class="Panther.Scheduling.ScheduledQuery+Parameter, panther.sched.nhibernate" />
</set>

<join table="ScheduledQueryLib">
<key column="ScheduledQueryID" foreign-key="ScheduledQueryID" property-ref="ScheduledQueryId"/>
<property name="Name" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"/>
<property name="ProcedureName" access="Panther.Scheduling.NHibernate.MUnderBarPropertyAccessor, panther.sched.nhibernate"/>
</join>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

using (tx = session.BeginTransaction ())
{
return session.Get <ScheduledQuery> (pk);
}

Name and version of the database you are using: MsSql2005

The generated SQL (show_sql=true):

SELECT scheduledq0_.ScheduleRecurrenceID as Schedule1_4_0_, scheduledq0_.SendOnEmpty as SendOnEm2_4_0_, scheduledq0_.SendOnError as SendOnEr3_4_0_, scheduledq0_1_.Name as Name5_0_, scheduledq0_1_.ProcedureName as Procedur3_5_0_ FROM MessageScheduleRecurrenceQuery scheduledq0_ inner join ScheduledQueryLib scheduledq0_1_ on scheduledq0_.ScheduleRecurrenceID = scheduledq0_1_.ScheduledQueryID WHERE scheduledq0_.ScheduleRecurrenceID=?

I was hoping for this to actually generate:

SELECT scheduledq0_.ScheduleRecurrenceID as Schedule1_4_0_, scheduledq0_.SendOnEmpty as SendOnEm2_4_0_, scheduledq0_.SendOnError as SendOnEr3_4_0_, scheduledq0_1_.Name as Name5_0_, scheduledq0_1_.ProcedureName as Procedur3_5_0_ FROM MessageScheduleRecurrenceQuery scheduledq0_ inner join ScheduledQueryLib scheduledq0_1_ on scheduledq0_.[b]ScheduledQueryID[\b]=scheduledq0_1_.ScheduledQueryID WHERE scheduledq0_.ScheduleRecurrenceID=?

If I change it to that and run it in Server Management Studio, it comes back with a result, but without the change I get nothing. This is because ScheduledQueryID on the MessageScheduleRecurrenceQuery table is a foreign key into the ScheduledQueryLib table but the <join> tag seems to be assuming that it goes the other way.

Does anyone have any ideas on how to achieve the desired behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Please create a JIRA issue referencing this thread. Thanks.

Karl

PS: The <join> feature is still under development and shall be considered experimental at this time.

_________________
Karl Chu


Top
 Profile  
 
 Post subject: Re: Issue with join configuration
PostPosted: Thu Jul 09, 2009 12:51 pm 
Newbie

Joined: Thu Jul 09, 2009 12:33 pm
Posts: 1
Just set IsInverse property of the Join to True:
Code:
<join table="ScheduledQueryLib" IsInverse="True">
...
</join>

For more information, have a look to the source code: https://nhibernate.svn.sourceforge.net/ ... ng/Join.cs
Code:
public void CreateForeignKey()
      {
         // TODO: The "if (!IsInverse)" condition is not in H3.2.
         // Not sure if this H3.2 does it in a different way.  The reason
         // this condition is put in is because when a <join> is mapped with
         // inverse="true", the joined rows should not be deleted (see
         // comments in NH-466).  In other words, the joined row is
         // outside of the parent row's life cycle.  If this foreign
         // key is added, the parent row cannot be deleted independent
         // of the joined row.  Perhaps we need more clarification
         // on how this should behave.
         if (!IsInverse)
         {
            Key.CreateForeignKeyOfEntity(persistentClass.EntityName);
         }
      }

Regards.
Ben.


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.