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.
source share