Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistence Error Message: An instance of a null PK has been incorrectly provided for the find operation

I am trying to use Netbeans 7.01 to follow a tutorial on JSF 2.0 and JPA. I am using oracle XE and JDBC_6. I used JSF pages from entities wizard to generate my JSF pages. Everything works fine as I can retrive data from the database and display them. However when I attempt to create or update a record in the database, I get this error:

An instance of a null PK has been incorrectly provided for the find operation

How is this caused and how can I solve it?

like image 953
Adedeeji Ojo Avatar asked Nov 28 '11 19:11

Adedeeji Ojo


2 Answers

This basically means that you did the following:

Entity entity = em.find(Entity.class, null);

Note that the PK is null here. To fix your problem, just make sure that it's not null.

like image 154
BalusC Avatar answered Oct 08 '22 02:10

BalusC


This may be because you are running a find operation on an entity that has not been persisted yet. In which situation, the @ID field (if it is autogenerated), will not have a value, ie. it will be null. You are then trying to find the entity, and as @BalusC points out, you are sending a null value into your find method.

like image 31
kevin the kitten Avatar answered Oct 08 '22 03:10

kevin the kitten