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.