openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Joysn <>
Subject @Id not loaded when loading an entity
Date Sat, 19 Feb 2011 23:07:50 GMT

when i load an entity the id value is not populated. The entity that was
created using the following test code has the id attribute set correct,
and i can verify this in the database table too, but when i re-read the
entity the id attribute is not populated.

        em = getEntityManagerFactory().createEntityManager();

        EntityTransaction tx = em.getTransaction();

        // insert order

        Order order = new Order();


        // verify if order was inserted correct

        final String query = "SELECT o FROM Order AS o WHERE o.status = ?1";

        Query q = em.createQuery(query);
        q.setParameter(1, "testStatus");

        Order orderLoaded = null;
        orderLoaded = (Order) q.getSingleResult();

        assertTrue(orderLoaded.getId() > 0);
        assertEquals(order.getStatus(), orderLoaded.getStatus());

i am using OpenJPA 2.0.1 with MySQL JDBC 5.1.10 and MySQL Server 5.1.49.
with the following entity:

public class Order implements Serializable {

    /** serial for Serializable */
    private static final long serialVersionUID = -8061887078955032972L;

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    private int version;

    @Column(nullable = false, length = 50)
    private String status;

    private Date created;

    ... remaining code skipped ...

as i am not able to find a solution via the docs and using the internet, can
anybody help on why
the id column is not populated?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message