-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need help with <join>
PostPosted: Thu May 19, 2005 6:04 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
How am I gonna do this in hibernate:

Code:
select a.person_name, b.address, b.zip, from Person a, Address b where a.address_id = b. address_id


I tried <join> but that didnt work, Im using hibernate2.
//My Class:
Code:
package za.co.easypay.easycredit;
public class Person {
   
   private int id;
   private String name;
   private String address;
   private String zip;
   public Person() {
      super();
   }

   public String getAddress() {
      return address;
   }
   public void setAddress(String address) {
      this.address = address;
   }
   public int getId() {
      return id;
   }
   public void setId(int id) {
      this.id = id;
   }
   public String getName() {
      return name;
   }
   public void setName(String name) {
      this.name = name;
   }
   public String getZip() {
      return zip;
   }
   public void setZip(String zip) {
      this.zip = zip;
   }
}


//My Mapping File
Code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="za.co.easypay.easycredit.Person"
        table="Person"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >
        <id
            name="id"
            column="person_id"
            type="int"
            unsaved-value="null"
        >
            <generator class="assigned"/>
        </id>
        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
        />
        <join table="address">
           <key column="address_id"/>
           <property name="zip" column="zip"/>
           <property name="address" column="address"/>
        </join>
    </class>

</hibernate-mapping>

//The sql generated
Code:
Hibernate: select person0_.person_id as person_id, person0_.name as name from Person person0_


Am I doing something wrong, I did read the manual at 6.1.17 but that didnt help much.


Top
 Profile  
 
 Post subject: Got it!
PostPosted: Thu May 19, 2005 9:30 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
I got it working, had to upgrade to hibernate3. Now I have a diffrent problem. The join matches the key I specify to the ID of the class, issnt there some way to specify differently?

Current SQL:

select person0_.person_id as person1_, person0_.name as name2_, person0_1_.zip as zip3_, person0_1_.address as address3_ from Person person0_ inner join address person0_1_ on person0_.person_id=person0_1_.address_id


Prefered SQL:

select person0_.person_id as person1_, person0_.name as name2_, person0_1_.zip as zip3_, person0_1_.address as address3_ from Person person0_ inner join address person0_1_ on person0_.address_id=person0_1_.address_id


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