-->
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: Joining multiple tables
PostPosted: Mon Apr 02, 2012 6:34 am 
Newbie

Joined: Mon Apr 02, 2012 6:07 am
Posts: 1
Hi everyone,

I'm new to Hibernate (even in JAVA), and I'm having some doubt's about one thing. I created 2 tables in PostgreSQL with 1 to many relationship, and now i'm trying to test some queries to them. Tables names are TbPessoa (one) and TbTelefone(many).

TbPessoa - idPessoa(pk), usNome(charvar), usIdade(int), usTelefone(int)

TbTelefone - idTelefone(pk), usIOperadora(charvar), usTarifario(charvar), usData(date), idPessoa(int)

Foreign Key on TbTelefone referencing TbPessoa (idPessoa to idPessoa on TbPessoa).

I'm trying to create a query where I would get the items where usNome='Peter' OR usOperadora='Vodafone' like we can do with SQL statments like,

SELECT usNome, usOperadora
FROM TbPessoa, TbTelefone
WHERE usNome='Peter' OR usOperadora='Vodafone'

Finnaly, I need to know how a can print (using System.out.println) the query results. I've been using (just for one table) this:

transaction = session.beginTransaction();

@SuppressWarnings("unchecked")

String query = "SELECT FROM TbPessoa";
List <TbPessoa> lista = session.createQuery(query).list();

int i=0;

for( TbPessoa x : lista ) {

System.out.println( "Id: " + x.getIdPessoa() + "| Nome: " + x.getUsNome() + "| Idade:" + x.getUsIdade() + "| Morada: " + x.getUsMorada() + "| Nr. Telefone: " + x.getUsTelefone() );

i=i+1;

}



Sorry my bad English! Thanks!

Kind Regards,

Raul


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.