-->
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.  [ 11 posts ] 
Author Message
 Post subject: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 2:37 pm 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
hi all,

can any one light me how to retrieve the values form more than one table based on the conditions.

Thanx in advance

Bala


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 3:04 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
if you want to just select values, you can use the select statement

select value1, value2, from table1 table2 where condition 1 and/or condition 2

i.e.

select u.name, j.title from User u, job j where u.name = 'john' and j.code = 3

Also, you can join tables in a join statement (page 147 in the manual)

select mother, offspr, mate.name
from DomesticCat as mother
inner join mother.mate as mate
left outer join mother.kittens as offspr


Top
 Profile  
 
 Post subject: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:07 pm 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
hi,

If it's possible to write in the Spring Application.

my Problem is I have 3 Different POJO's i want to retrieve the Value from that.


Bala


Top
 Profile  
 
 Post subject: Re: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:19 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
Balasubramanaim wrote:
hi,

If it's possible to write in the Spring Application.

my Problem is I have 3 Different POJO's i want to retrieve the Value from that.


Bala


I am not sure of what you are asking. Are you trying to eager fetch all of the three objects?

If you want to eager fetch, you can call

Hibernate.initialize() to initialize your objects before you close your session.


Top
 Profile  
 
 Post subject: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:27 pm 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
hi,
Code:
[color=red]String query = "from CompanyAddress EAN_COMPANY_ADDRESS where COMPANY_ID = ?";
      CompanyAddress companyAddress = null;
      Object[] parameters = { companyID };
      List list = this.getHibernateTemplate().find(query, parameters);
      if(list.size()>0) {
         companyAddress = (CompanyAddress) list.get(0);
      }
[/color]

The above is my code.

Based on the Company_ID i retreive the Value from the Company_Address table in one scenario.

In my second scenarion i want to retrieve the Country name and State name from the table Country and state respectively based on the Company_Code
how can i do it.


Bala


Top
 Profile  
 
 Post subject: Re: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:36 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
Balasubramanaim wrote:
hi,
Code:
[color=red]String query = "from CompanyAddress EAN_COMPANY_ADDRESS where COMPANY_ID = ?";
      CompanyAddress companyAddress = null;
      Object[] parameters = { companyID };
      List list = this.getHibernateTemplate().find(query, parameters);
      if(list.size()>0) {
         companyAddress = (CompanyAddress) list.get(0);
      }
[/color]

The above is my code.

Based on the Company_ID i retreive the Value from the Company_Address table in one scenario.

In my second scenarion i want to retrieve the Country name and State name from the table Country and state respectively based on the Company_Code
how can i do it.


Bala


Does the company_address table has a relationship to country table and the sate table?


Top
 Profile  
 
 Post subject: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:44 pm 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
Yes, three tables are interlinked,

Company_Address - Country_code and State_id is available

Country - Country_Code is Primary Key

State - State_ID is primary Key

Bala


Top
 Profile  
 
 Post subject: Re: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 3:51 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
hannah wrote:
Balasubramanaim wrote:
hi,
Code:
[color=red]String query = "from CompanyAddress EAN_COMPANY_ADDRESS where COMPANY_ID = ?";
      CompanyAddress companyAddress = null;
      Object[] parameters = { companyID };
      List list = this.getHibernateTemplate().find(query, parameters);
      if(list.size()>0) {
         companyAddress = (CompanyAddress) list.get(0);
      }
[/color]

The above is my code.

Based on the Company_ID i retreive the Value from the Company_Address table in one scenario.

In my second scenarion i want to retrieve the Country name and State name from the table Country and state respectively based on the Company_Code
how can i do it.


Bala


Does the company_address table has a relationship to country table and the sate table?


try this:

select c.ean_company_address, c.state.name, c.country.name from companyAddress c where c.company_code = 87


Top
 Profile  
 
 Post subject: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 4:03 pm 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
" from CompanyAddress EAN_COMPANY_ADDRESS where COMPANY_ID = ? "

one info in the above line CompanyAddress is my POJO name and EAN_COMPANY_ADDRESS is my table name.

if i using that line in which POJO i will use to retrieve it.


Bala


Top
 Profile  
 
 Post subject: Re: Retrieving the Multiple Values
PostPosted: Fri May 11, 2007 4:15 pm 
Beginner
Beginner

Joined: Fri Apr 13, 2007 9:27 am
Posts: 33
Balasubramanaim wrote:
" from CompanyAddress EAN_COMPANY_ADDRESS where COMPANY_ID = ? "

one info in the above line CompanyAddress is my POJO name and EAN_COMPANY_ADDRESS is my table name.

if i using that line in which POJO i will use to retrieve it.


Bala


You have to look into your .hbn configuration file. Each table should be mapped to a Bean, and each table column should be mapped to a Bean property. You don't use table name in HQL, you use the Bean name and its properties.


Top
 Profile  
 
 Post subject: Retrieving the Multiple Values
PostPosted: Sat May 12, 2007 10:26 am 
Newbie

Joined: Fri May 11, 2007 2:24 pm
Posts: 7
Location: Coimbatore, India
I couldn't know that how will i proceed that.

Bala


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