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
|