Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how can i join two different table

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my first hibernate program. and i read some of the tutorial. but still i struggled

i have table A which has two column such as id and name here id is an primary key (and)

table B which has two column such as id and email here id is an primary key

now i need to fetch A.name and B.email from tables A and B based on id . i tried but failed to obtain the data .

please anyone can tell me the way to achieve it ?



 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So is there is not relationship between these tables? Or is it one to one?

Can you post what you tried?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well,relation is one-to-one.

Here is my UserName.hbm.xml[For database table A]



and UserName.java[javabean]




and UserMail.hbm.xml[For database table B]



and UserMail.java[java bean]



and finally hibernate.cfg.xml



and i create a java class to test the application

Execute.java [assume it HibernateUtils class is fine]




Now it is working fine for retrieve the values from table A only.. now please see my question in my first post[how to inner join and get the datas]

Sorry for the long post
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you need to define this association in your mapping file and you do this with the one-to-one mapping. Have a read of that link, it includes a few examples.

(One question - why are you using Hibernate 2? Its a bit old. )
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot .

Paul Sturrock wrote:(One question - why are you using Hibernate 2? Its a bit old. )



Yes . really i need to switch to Hibernate 3
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in Hibernate Query , i need to fetch the records from two table. example,

select a.name,b.email from A as a,B as b where a.id=b.id



how to execute this query and how to get the values from the tables .



Problem here UserName and ,UserMail are created and i am only casting in to the UserName . so i am getting classcastException

any help ?
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your "alist" will be a List of Object[]
So, it should be List<Object[]>
and when you iterate over this list, in each iteration, you get an Object[], cast the first element of the array to type of "a.name" and second element to "b.email" and create the required objects.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its worth having a read through the documentation. It includes a tutorial too, so you'll probably save yourself a good deal of hassle.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul and Rahul
reply
    Bookmark Topic Watch Topic
  • New Topic