Hello, When persisting an entry, you may not put a value in your PK if it is a generated key!
Likely you have, somewhere, something like this: @Entity public class Member { .... @ID @GeneratedValue(...) private ... userId; And, in the populating method: Member member = new Member(); member.setUserId(fromXmlMember.getUserId()); <- do not do this! ... Em.persist(member); Hope this helps,  John ---- Who is General Failure, and why is he reading my hard disk? > -----Ursprüngliche Nachricht----- > Von: schamarthi [mailto:srinivas.chamar...@gmail.com] > Gesendet: Dienstag, 22. Mai 2012 00:40 > An: users@openjpa.apache.org > Betreff: Exception during the unit tests in Eclipse(including maven) > > I am populating data from xml and persisting entities using > entitymanager during my application startup and everything is > fine. But however I am trying to run the junits with setup > containing the script to load the test data by persisting > them using entitymanager, I am seeing the following exception... > > PS: I haven't set any userId value in my unit tests. > > not sure what does this mean.... am not able to get away with > this exception. appreciate any quick help. > > > Primary key field com.all4u.server.domain.Member.userId of > com.all4u.server.domain.Member@187e184 has non-default value. > The instance life cycle is in PNewState state and hence an > existing non-default value for the identity field is not > permitted. You either need to remove the @GeneratedValue > annotation or modify the code to remove the initializer > processing.; nested exception is > <openjpa-2.2.0-r422266:1244990 nonfatal user error> > org.apache.openjpa.persistence.InvalidStateException: Primary > key field com.all4u.server.domain.Member.userId of > com.all4u.server.domain.Member@187e184 has non-default value. > The instance life cycle is in PNewState state and hence an > existing non-default value for the identity field is not > permitted. You either need to remove the @GeneratedValue > annotation or modify the code to remove the initializer processing. > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Exception-during-the-unit- > tests-in-Eclipse-including-maven-tp7570130.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >