• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refresh()/Flush() error after Persist()

 
Maria Michael
Greenhorn
Posts: 18
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Every day I find a different difficulty with JPA that I have to cope with but that how it is with beginners i suppose.

I am customizing the CRUD application of Netbeans.

This works:




If I call flush after persist I get:

Exception Description: Null or zero primary key encountered in unit of work clone [myapp.entityclasses.Persontbl[ personId=null ]], primary key [null]. Set descriptors IdValidation or the "eclipselink.id-validation" property.

If I call refresh() after persist I get:

Entity no longer exists in the database: myapp.entityclasses.Persontbl[ personId=null ]


Any ideas?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you set the Id of the person before you call persist?
What is the Id, how is it mapped? Include the annotations/xml.

Seems like you didn't set the id, but left it as null or 0. Maybe you want to use a @GeneratedValue.
Possibly, you are persisting some other object that references a person that has no id, maybe you need to persist the person first?
 
Maria Michael
Greenhorn
Posts: 18
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really.. thank you.

I did not add the @GeneratedValue(strategy=GenerationType.IDENTITY) as I should.

I was so certain that I did and when you asked I checked and I didn't....

Again thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic