-->
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: HQL - Look for a particular entity inside a Java object
PostPosted: Wed Mar 06, 2013 6:55 am 
Newbie

Joined: Wed Mar 06, 2013 5:39 am
Posts: 1
Hi guys,

I'm trying to do a Java method able to retrieve a list of orders (Pedido class) that contain a certain entity called Usuario. I have the following entities in Java:

Code:
public class Pedido implements java.io.Serializable {
   
   private static final long serialVersionUID = 1L;
   
   private Usuario usuario;
   private int numeroPedido;
   private Calendar fechaPedido;
   private String estadoPedido;
   private double precioPedido;
   private Set<PedidoPizza> pizzas;
......


Code:
public class Usuario implements java.io.Serializable {
   
   private static final long serialVersionUID = 1L;
   
   private int idUsuario;
   private String email;
   private String password;
   private boolean admin;
   private String nombre;
   private String apellido1;
   private String apellido2;
   private String direccion;
   private String codigoPostal;
   private String poblacion;
   private Set<Pedido> pedidos = new HashSet<Pedido>();
.....




I have the following query that provides valid results when used on Hibernate Tools in eclipse:

Code:
from Pedido as Pedido inner join Pedido.usuario as Usuario where Usuario.idUsuario = 2



And this is the method that I tried to code in Java:

Code:
public List<Pedido> retrievePedidoByUser(Usuario usuario) {
      // TODO Auto-generated method stub
      List<Pedido> pedidos = null;
      Session s = getSessionFactory().getCurrentSession();
      pedidos = (List<Pedido>) s.createQuery("from Pedido as Pedido inner join Pedido.usuario as Usuario where Usuario = ?").setSerializable(0, usuario).list();
      return pedidos;
   }



Giving the following exception:

Code:
org.hibernate.exception.SQLGrammarException: could not execute query
......
Caused by: java.sql.SQLException: Wrong data type: java.lang.NumberFormatException: For input string: "[B@49b29f80"
......



I think that the query is fine, but I'm not coding correctly it in the Java method. I've looked for examples but I haven't found any showing how to look for an entity inside another entity, just particular values. I would prefer looking for the object instead of looking for a match in the idUsuario property as in the Hibernate Tools example query, but any advise about what I'm doing wrong would be fine.

Thanks in advance for your support.


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.