Lets say thay I have an entity with name “A”.It has two columns named as name and systemId.
These columns constraint unique key.For example it does not allow duplicate entities with systemId “1” and name “test”.
My question is: I want to insert Collection of A entities.I want to skip duplicate entities just insert new ones.Is EntityManager able to skip these entities if unique constraint fails?
How can I succeed this?
JPA does not allow for error handling, it requires that a transaction be marked for rollback if any error occurs.
You could insert each in a separate transaction, or put the whole transaction in a retry and reject the objects that fail on each pass. You could also do a select first on the unique fields and skip the object if it already exists.