JPA retrieved object id

I have a simple object with an integer id field:

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(unique = true, nullable = false) private int id; 

Objects can be stored in the database correctly. However, when retrieving an object from the database:

 EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("MyService"); EntityManager entityManager = emFactory.createEntityManager(); MyObject myObject = entityManager.find(MyObject.class, 1); entityManager.close(); 

The id field of the restored object is always zero, but the values โ€‹โ€‹of all other fields are extracted correctly.

If I remove the @Id annotation from the code, the value of the id field can be restored correctly, like all other fields.

I use OpenJPA with MS SQL Server 2008. Both the MS sqljdbc driver and the JTDS driver are checked.

+4
source share
1 answer

This is a known bug when expanding using the eclipse plugin. I highly recommend getting another enhancement build time method. Feel free to post additional questions on the OpenJPA user mailing list.

+3
source

All Articles