Hi there! I have been all day trying to solve this. I have read multiple sites and documentation, but I can go through this.
I have a clase named Pedido, that have a reference ManyToOne to a clase Cliente.
@Entity public class Pedido { @Id @GeneratedValue private long id; @Embedded private Direccion origen; @ManyToOne(optional=true) private Cliente cliente; //Opcional @Basic(optional=false) private Date fechaYhora; //Fecha en que se debe enviar el coche } @Entity public class Cliente extends Persona{ @OneToMany(mappedBy="Pedido.cliente") public List<Pedido> pedidos; } The class Persona, has nothing in special. Just a few variables. String, int, and an embedded class. The problem is that, when I try to get a list of Client, I get an error. static public List<Cliente> getClientes() throws Exception{ em = EMF.createEntityManager(); List<Cliente> results = null; try { TypedQuery<Cliente> query = em.createQuery("SELECT c FROM Cliente c", Cliente.class); results = query.getResultList(); } finally { em.close(); } return results; }
At the end of this method, "results" is null.Even affter the query. And on em.close() I get an exception:
com.objectdb.o._PersistenceException: Failed to write the value of field field entidades.Cliente.pedidos using reflection
What's wrong with this? I suppose i'm making a bad connection on the oneToMany - manyToOne. But I can't figure it out.
Someone can help me?