ObjectDB ObjectDB

Error: Failed to write value of field X using reflection (oneToMany relation)


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.

public class Pedido {
    @Id @GeneratedValue
    private long id;
    @Embedded private Direccion origen;
        private Cliente cliente; //Opcional
    @Basic(optional=false) private Date fechaYhora; //Fecha en que se debe enviar el coche


public class Cliente extends Persona{
       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 {
    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?


Please provide a complete test case that demonstrates the exception using the format in these instructions.

ObjectDB Support

First at all, thank you for answering. And sorry for late answer. I was making a lot of tests. At first the test was working. So I belived it was a mistake on my code. I spended a lot of time searching for it.

But after, I tried a test case without the drop option when creating the database. And there is when the error shows up.

So, the program works fine on the first run. But after that I recieve the "Failed to write the value of field field testodb2.TestODB2$Cliente.pedidos using reflection"

The test case file is adjunct.


You have to change the value of the mappedBy attribute:


i.e. specify the field name on the owner side without the class name.


ObjectDB Support


To post on this website please sign in.