I tried using @IdClass for this and regular @Version annotation on the version field but i keep getting the Error:
OptimisticLockException: Attempted to attach deleted instance type "class xxx" with oid "xxx". If the instance is new, the version field should be left to its default value
After the EntityManager.merge(obj) line. I have two PK's that are integers, so is the version field... i use a PK- Class that has the Id fields with @IdClass(Pk.class) and the setter and getter for the Id's are calling an instance of the Pk class that is created in the constructor. I'm not using @GeneratedId. I'm using Openjpa not Hibernate.
Probably your app. is changing version field. It should be never set. It is a technical column. Without pasting code here, is just a guess.