ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Poitras Christian" <Christian.Poit...@ircm.qc.ca>
Subject RE: Urgent help Needed - Join Query
Date Tue, 18 Apr 2006 16:10:24 GMT
First, I believe you should make a link between your 2 objects.
 
In User add a List property that will contain user addresses. With this
solution it will be easy to populate User and Address List at the same
time.
Also add this in the User resultMap.
<result property="addressList" column="userId" select="getAddressByUser"
/>
And the query "getAddressByUser" will contain
select * from User, Address  where User.UserId = Address.UserId and
User.UserId = #value#
 
You can also populate the User and it's Addresses in one call.
 
Christian
Christian.Poitras@ircm.qc.ca
 
________________________________

From: rambabu.piridi@wipro.com [mailto:rambabu.piridi@wipro.com] 
Sent: Tuesday, 18 April 2006 11:22
To: user-java@ibatis.apache.org
Subject: Urgent help Needed - Join Query


 
Hi,
 
   I have two tables  User and Address. The primary key of the User
table is also the foreign key of Address table.
 
It is possible that a user may or may not have address ( Property )
associated with him and also one user can have more than one address
(property). I have two Java classes which are useful to set and get the
values of  the data members.
 
 
public class User {
 
         private String UserId ;
         private String UserName;
         private String Designation;
         private String Address;
 
 public String getAddress() {  return Address; }
 
 public String getDesignation() {  return Designation; }
 
 public String getUserId() {  return UserId; }
 
 public String getUserName() {  return UserName; }
 
 public void setAddress(String address) {  Address = address; }
 
 public void setDesignation(String designation) {  Designation =
designation; }
 
 public void setUserId(String userId) {  UserId = userId; }
 
 public void setUserName(String userName) {  UserName = userName; }

}

 
public class Address
 {
 
 private String UserId;
 private String City;
 private String State;
 
 public String getCity() {  return City; } 
 
 public String getState() {  return State; }
 
 public String getUserId() {  return UserId; }
 
 public void setCity(String city) {  City = city; }
 
 public void setState(String state) {  State = state; }
 
 public void setUserId(String userId) {  UserId = userId; }
 
}

 
The following table shows the structure of the table.
 
User
===============
UserId  - PrimaryKey
UserName
Designation
Address
 
 
Address
===============
UserId - ForeignKey
City
State
 
 
the following table data is an example data.
 
User
======================================================
UserId                UserName               Designation
Address
 
    1                    Abc                        S.E
City, New Yark                          
    2                    Xyz                         S.E
---              
    3                    Cde                        P.M
----
  
 
 
Address 
=======================================================
UserId                PropertyName         PropertyName 
 
    1                    City                        New Yark

    1                    Country                   America

    2                    --                               ---

    3                    City                         NewYark

    4                    City                         London

 
 
When I am trying to get the data from both the tables using the
following Query
 
select * from User, Address  where User.UserId = Address.UserId
 
the result is 
 
1, Abc , S.E                  
1, City, New Yark                          
1, Country, America                           
        
           Now my requirement is to get the data from both the tables
and store them as User Object. 
Can any one specify 
 
                             1. IBatis SQL Mappings for the tables.
 
                             2. SQL Qury to get the data from both the
tables and store it in User Object.
 
 
 
regards,
 
rambabu

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
	

Mime
View raw message