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?
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With