-->
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.  [ 1 post ] 
Author Message
 Post subject: LEFT JOIN where the foreign key constist of 2 fields
PostPosted: Wed May 04, 2005 10:12 am 
Beginner
Beginner

Joined: Wed Oct 29, 2003 10:43 am
Posts: 38
Location: Chicago
Hello,

I am using Hibernate3.
The following iare simplified hbm files:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="Table1"
table="TABLE_1">

<id
name="primaryKey"
type="java.lang.String"
column="PRIMARY_KEY">
<generator class="assigned" />
</id>

<property
name="departmentNo"
type="java.lang.String"
column="DEPARTMENT_NUMBER"
length="65"/>

<property
name="groupNo"
type="java.lang.String"
column="GROUP_NO"
length="65"/>
</class>
</hibernate-mapping>


**************************************************

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="Table2"
table="TABLE_2">

<composite-id>
<key-property
name="departmentNumber"
column="DEPTARTMENT_NUMBER"
type="java.lang.String"
length="65"/>
<key-property
name="groupNumber"
column="GROUP_NUMBER"
type="java.lang.String"
length="65"/>
</composite-id>
<property
name="description"
type="java.lang.String"
column="DESCRIPTION"
length="65"/>
</class>
</hibernate-mapping>


********************************************************

I would like to select Table1 and Table2 by linking departmentNumbers
and groupNumbers.

can i add something liek this to Table1?
<one-to-one
name="table2"
class="Table2"
lazy="true">
<column_name>DEPARTMENT_NUMBER</column_name>
<column_name>GROUP_NUMBER</column_name>
</one-to-one>

ANd select like this?

SELECT table1 FROM Table1 table1
LEFT JOIN FETCH table1.table2

DO I use the POJO column idetifiers or the DB Field Names?
<one-to-one
name="table2"
class="Table2"
lazy="true">
<column_name>departmentNumber</column_name>
<column_name>groupNumber</column_name>
</one-to-one>

Do I need to add anything to Table2's definition?

IF this is not possible how would I write the HQL to fetch both objects without the one-to-one association?

THanks for your help

_________________
LET IT BE :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.