-->
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.  [ 6 posts ] 
Author Message
 Post subject: I need help making a Criteria question with Join
PostPosted: Wed Jan 21, 2009 10:38 am 
Newbie

Joined: Wed Jan 21, 2009 9:36 am
Posts: 5
I need make this SQL question with Criteria.

SELECT a.id_
FROM
vsc_userversion AS a
JOIN vsc_usuario AS b
on a.idusuario = b.id_ and b.nombre = "xxx"




I try with this but doesn't work for me. How can i get a join in Criteria sintaxys?

criteria.createAlias("Usuario", "idusuario",JoinFragment.FULL_JOIN);
Criteria user = criteria.createCriteria("idusuario");
user.add(Restrictions.eq("nombre", this.params.get("nb")));
criteria = user;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 12:55 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Let me see if I can decipher your entity names

Code:
Criteria criteria = session.createCriteria(UserVersion.class);
criteria.createAlias("Usario", "usarioAlias);
criteria.add(Restrictions.eq("usarioAlias" + "." + "nombre", this.params.get("nb"));

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 1:08 pm 
Newbie

Joined: Wed Jan 21, 2009 9:36 am
Posts: 5
I'm sorry but thast doesn't work for me :(. I have two tables (Userversion and Usuario) And I want to make a Join between this tables. When i put your code the console dispatch this:

14:03:28,315 ERROR [STDERR] org.hibernate.QueryException: could not resolve property: Usario of: cl.vsoft.liferay.domain.Userversion

the primary key id_ in Usuario tables is the foreign key idusuario in Usuario

Do you know what is the problem?

PD: I'm sorry for my bad inglish


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 1:16 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Could you post your classes, please?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 1:20 pm 
Newbie

Joined: Wed Jan 21, 2009 9:36 am
Posts: 5
//Userversion

public class Userversion implements java.io.Serializable,IDomainObject,IJson,ICombobox
{

private Long id;
private String idusuario;
private String idinstancia;
private String nombre;
private String idversion;
private String idproceso;
private String apellido;
private String username;
private String version;
private String proceso;
private long idUsuario;
private long idVersion;


public Userversion()
{
}

//Usuario

public class Usuario implements IDomainObject
{
private Long id;
private long identidad;
private boolean identidadNull = true;
private String username;
private String email;
private String nombre;
private String apellidopaterno;
private String apellidomaterno;

private Date fechaNacimiento;

/**
* Method 'Usuario'
*
*/
public Usuario()
{
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 10:20 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You need to have an association mapped between UserVersion and Usario, it looks like you only have the entity mapped by just the id which isn't going to work.

Look at one-to-many and many-to-one in the reference documentation.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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