I have a simple object with an integer id field as followings:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
private int id;
Objects can be persisted into database correctly. However, when retrieving object from the database by:
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("MyService");
EntityManager entityManager = emFactory.createEntityManager();
MyObject myObject = entityManager.find(MyObject.class, 1);
entityManager.close();
The id field of a retrieved object is always zero, but values of all other fields are retrieved correctly.
If I remove the @Id annotation from the code, the value of id field can be retrieved correctly just like all other fields.
I’m using OpenJPA with MS SQL Server 2008. Both MS sqljdbc driver and JTDS driver are tested.
This is a known bug when enhancing using the eclipse plugin. I’d highly recommend getting another method of build time enhancement going. Feel free to post additional questions to the OpenJPA users mailing list.