-->
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.  [ 2 posts ] 
Author Message
 Post subject: Search with Criteria in a one-to-one Relationship
PostPosted: Sat Mar 05, 2011 6:08 pm 
Newbie

Joined: Thu Feb 17, 2011 5:08 pm
Posts: 6
Hi people...

I need to search with Criteria the Personas with a Cliente relationship...

my tables are

Persona
- id
- nombre

Cliente
- id (Fk of Persona)
- creditLimit

the HBMs are
in Persona
<one-to-one cascade="all-delete-orphan" name="cliente" />
in Cliente
<one-to-one constrained="true" name=persona />

How can I search Personas with a Cliente relationship??

for example
Table Personas
ID nombre
1 uno
2 dos
3 tres

Table Cliente
ID creditLimit
2 100

i need obtain as result only the Persona with Id 2...


Thanks in advance and sorry... my English is pretty poor

Nicolas


Top
 Profile  
 
 Post subject: Re: Search with Criteria in a one-to-one Relationship
PostPosted: Mon Mar 07, 2011 6:42 am 
Newbie

Joined: Mon Mar 07, 2011 6:32 am
Posts: 3
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("propertyname in persona class"));
Criteria c = session.createCriteria(Persona.class);
c.setProjection(proList);
c.addOrder(Order.asc("some property name in persona class"));
List clients = c.createCriteria("Cliente").add(Property.forName("creditLimit").eq("100")).list();
session.getTransaction().commit();
for(Iterator it =
client.iterator();it.hasNext();){
Object[] row = (Object[])it.next();
}

You can change it according to your need :)


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