I have a small doubt on this: How come the persistent provider knows that the entity which would be persisted already exist in the database? Lets say I am persisting an entity. Would the persistent provider checks the entire table if there is a row with the same values that the entity which is going to be persisted exists in that particular table? Please excuse if this is not the related forum to post this question
------------------------------------- LakshmiNarayana Kodali SCJP 5(98%), SCWCD(100%), SCBCD in progress
Joined: Aug 28, 2006
Why would the DB gives primary key constraint exception? lets say I have an Employee bean with properties name and salary. I can insert an employee with name as 'XXX' salary as 1000. I can insert an employee again with name as 'XXX' and salary as 1000. The DB won't raise any primary key constraint over here. The DB may give unique exception if I make the name as unique.
Well. the Relational Databases Laws state that every row in the table must be uniquely identified, i.e. each table should have a primary key.. That is the reason you have to specify a field with the @id notation while mapping it to a database. that field with @id notation becomes the primary key. The example in your case does not have any primary key, and i am not sure how could you use the Java Persistence API in such a case.