-->
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.  [ 14 posts ] 
Author Message
 Post subject: Join element like hibernate.
PostPosted: Mon Jun 25, 2007 12:02 pm 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

NHibernate version:
1.2.0 GA

Hello:

Is there a way to simulate the Hibernate join element (as described in 5.1.18 http://www.hibernate.org/hib_docs/v3/re ... pping.html) in NHibernate ?

I haven't found a way to do it.

Regards

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You can find this feature in the current trunk. If you only want this feature without the other bleeding edge features in the current trunk, you can download and apply the patch to the 1.2 GA source code. You can find the patch at this JIRA issue:

http://jira.nhibernate.org/browse/NH-466

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 10:09 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
Hi Karl.

I was trying to patch my existing hibernate version, but it sounds a little difficult to me (very new bie).

How can i make the join table work for my solution?

I tried to download the http://jira.nhibernate.org/secure/attac ... 2594.patch
file, but i don't know how to apply it to my code.

Any help please?

Kind regards

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 6:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Hi Massimo,

Download TortoiseSVN from http://tortoisesvn.tigris.org. Then you can check out the current trunk or the 1.2GA source code. Download the patch, apply it, and then recompile NHibernate. It all this sounds foreign to you, I would suggest you learn more about version control and Subversion in general (http://svnbook.red-bean.com/). Good luck.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 3:17 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
karlchu wrote:
Hi Massimo,

Download TortoiseSVN from http://tortoisesvn.tigris.org. Then you can check out the current trunk or the 1.2GA source code. Download the patch, apply it, and then recompile NHibernate. It all this sounds foreign to you, I would suggest you learn more about version control and Subversion in general (http://svnbook.red-bean.com/). Good luck.


Thank you Karl. I use svn as scm for work; so right now I downloaded the nhibernate source: now i'm trying to apply the patch but i don't know which one (NH466_r2826.patch or any else ?).
I downloaded the NH466_r2826.patch but now i don't know how to apply it.
Is there any reference to make this task?

Kind regards

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 3:22 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
m.ugues wrote:

I downloaded the NH466_r2826.patch but now i don't know how to apply it.
Is there any reference to make this task?



Ok i found the right patch (i suppose the NH466_r2826.patch) and how to apply it via tortoise.

I hope this is going to work.

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 4:23 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
Ok I applied the patch.

Right now i tried to compile nhibernate with nant but i got an error.

Any way to have a patched nhibernate dll?

Kind regards

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 8:37 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
karlchu wrote:
Hi Massimo,

Download TortoiseSVN from http://tortoisesvn.tigris.org. Then you can check out the current trunk or the 1.2GA source code. Download the patch, apply it, and then recompile NHibernate. It all this sounds foreign to you, I would suggest you learn more about version control and Subversion in general (http://svnbook.red-bean.com/). Good luck.


Hallo karl, i got this problem.

I checked out nhibernate from the tags 1.2.0 GA as you suggested me (the revisione showed under log is the 2798).

I downloaded the patch NH466_r2826.patch and tried to apply it but i got a lot of error during the process. (i.e. The patch seems outdated...)

During the applying I selected to apply it to all files (patch all).

So I downloaded the revision 2826 thinking that was the correct revision to patch (since the name of the patch is r2826) and the patch worked (I applied also the JetCaseFragment_r2826.patch).

Then I re compiled nhibernate as suggested (NAnt -D:project.config=release clean build >output-release-build.log) and build was succeded.

Then i changed all the dll that i was using (NHibernate.dll, Iesi.Collections.dll, Castle.DynamicProxy2.dll) with new ones.

I changed the hbm.xml to use the new feature

<!-- Hibernate Way -->
<join table="Ubicazioni">
<key column="UbicazioneID"/>
<property name="Ubicazione" column="Descrizione" type="string"/>
</join>

The problem is that for default it uses inner join (... inner join Ubicazioni ...) and when i load all the records from master table i got only a number of record equal to the join table record number.

Very strange. I don't know how to solve this problem, i tried to change the fetch attribute to join="select" but still got the same issue.

Any idea how to solve this problem?

Kind regards

Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 9:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I believe this will solve your problem:
Code:
  <join table="Ubicazioni" optional="true">

The documentation for <join> in NHibernate is not completed. You may use the Hibernate docs for now.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 4:17 am 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
karlchu wrote:
I believe this will solve your problem:
Code:
  <join table="Ubicazioni" optional="true">

The documentation for <join> in NHibernate is not completed. You may use the Hibernate docs for now.


Thanks karlchu, this worked out, but I think there's a problem.

I have one object described by this mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Anagrafica, it.telecomitalia.Gecko.BusinessEntities" table="Anagrafiche" lazy="false">
<id name="AnagraficaID" column="AnagraficaID">
<generator class="identity" />
</id>

<join table="Ubicazioni">
<key column="UbicazioneID"/>
<property name="Ubicazione" column="Description" type="string"/>
</join>

</class>
</hibernate-mapping>

In code:

public class Anagrafica
{
private long anagraficaID;
// element on which i would like to make the join table
private string ubicazione;
......

So I have one table for Ubicazione with two columns UbicazioneID and Description and one table for Anagrafica class with a foreign key UbicazioneID.

When I try to test the join table attribute it seems that nhibenrate make the join on the Anagrafica PK instead of the FK as I can see from the logs:

SELECT anagrafica0_.AnagraficaID as Anagrafi1_2_1_ FROM Anagrafiche anagrafica0_ inner join Ubicazioni anagrafica0_1_ on anagrafica0_.AnagraficaID=anagrafica0_1_.UbicazioneID.

I think that the join clause anagrafica0_.AnagraficaID=anagrafica0_1_.UbicazioneID
should be
anagrafica0_.UbicazioneID=anagrafica0_1_.UbicazioneID

Am i wrong?

Kind regards

Massimo Ugues


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 1:01 pm 
Newbie

Joined: Mon Aug 06, 2007 12:57 pm
Posts: 4
Quote:
SELECT anagrafica0_.AnagraficaID as Anagrafi1_2_1_ FROM Anagrafiche anagrafica0_ inner join Ubicazioni anagrafica0_1_ on anagrafica0_.AnagraficaID=anagrafica0_1_.UbicazioneID.

I think that the join clause anagrafica0_.AnagraficaID=anagrafica0_1_.UbicazioneID
should be
anagrafica0_.UbicazioneID=anagrafica0_1_.UbicazioneID

Am i wrong?

Kind regards

Massimo Ugues


I'm running into this same issue, so i'm thinking me and Massimo have something wrong in our hbm mappings. Anyone have an example for joining a parent table inside a child?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 1:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Hi Massimo,

When using the <join> element, the joined table is essentially an extension of the main table related by the PKs. Therefore, the join clause that NHibernate generated is correct. In other words, the main table (Anagrafiche) and the joined table (Ubicazioni) should have a one-to-one relationship on the primary keys on both tables. If you have a foreign key (UbicazioneID) in your main table (Anagrafiche), my guess is that you really have a many-to-one association from the Anagrafiche table to the Ubicazioni table; and as such, you ought to use the <many-to-one> mapping. In that case, you may have misunderstood the usage and intent for the <join> mapping element.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 12:08 pm 
Newbie

Joined: Mon Jun 25, 2007 11:35 am
Posts: 15
karlchu wrote:
Hi Massimo,

When using the <join> element, the joined table is essentially an extension of the main table related by the PKs. Therefore, the join clause that NHibernate generated is correct. In other words, the main table (Anagrafiche) and the joined table (Ubicazioni) should have a one-to-one relationship on the primary keys on both tables. If you have a foreign key (UbicazioneID) in your main table (Anagrafiche), my guess is that you really have a many-to-one association from the Anagrafiche table to the Ubicazioni table; and as such, you ought to use the <many-to-one> mapping. In that case, you may have misunderstood the usage and intent for the <join> mapping element.


Hi Karlchu, I think that we got some misunderstanding.

...the main table (Anagrafiche) and the joined table (Ubicazioni) should have a one-to-one relationship on the primary keys on both tables.

<join table="Ubicazioni">
<key column="UbicazioneID"/>
<property name="Ubicazione" column="Descrizione" type="string"/>
</join>

As you can see the key attribute (<key column="UbicazioneID"/>) is useful to describe in the master table the "key column" used to make the join in the join table.

If what you told is true, I think that should be unnecessary using the "key column" attribute if the two tables (main and join one) should share the PK (since nhibernate should know them).

I think that key attribute is useful to reach the purpose.
Infact it could be used to make the correct join between the main table and the slave one:
[left] join Anagrafica.<key> = Ubicazione.<id>


What do you think about?

Kind regards

Massimo Ugues

Massimo Ugues


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Hi Massimo,

NHibernate only knows about the PKs if you tell it so. The <key> element inside the <join> element describe the column in the joined table (i.e. Ubicazioni), not in the main table (Anagrafiche). Using the example in the Hibernate doc:
Code:
<class name="Person" table="PERSON">

    <id name="id" column="PERSON_ID">...</id>

    <join table="ADDRESS">
        <key column="ADDRESS_ID"/>
        <property name="address"/>
        <property name="zip"/>
        <property name="country"/>
    </join>
    ...


The database tables will look like this:
Code:
CREATE TABLE PERSON (
  PERSON_ID IDENTITY(1,1),
  ...
)

CREATE TABLE ADDRESS (
  ADDRESS_ID int,
  address varchar(255),
  zip varchar(10),
  country varchar(255)
)


If there is a person "Karl Chu" in the PERSON table and his ID is 10, then Karl Chu's address is stored in the ADDRESS table and the ADDRESS_ID also has a value of 10.

Hope this illustrates the usage.

_________________
Karl Chu


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