Hi!
I'm having a problem when a RollbackException occures after trying to remove
an Entity which is not allowed to be removed because of an Foreign Key Restrict Constraint.
In Detail:
- I've got two Tables in my DB: Postalcode and Country
- Postalcode references to Country by a Foreign Key Constraint
- It shouldn't be possible to remove a Country which is used in a Postalcode row
When i try to remove a Country entity which isn't used in Postalcode everything works
as expected.
When i try to remove a Country which is used in Postalcode i get an RollbackException,
this is also what i want and expect.
Now the Problem:
After trying to remove an Referenced Entity and handling the RollbackException i am trying
to remove an unreferenced Entity - but then i get the following Exception:
java.lang.IllegalArgumentException: Entity must be managed to call remove: Afg (FAG), try merging the detached and try the remove again.
Removing unreferenced Entities prior to removing referenced Entities works fine. This happens
only after trying to remove an referenced Entity.
Why do the Entities get unmanaged?
I've already tried to do a merge() before deleting, but this results in the same error.
Here's what i am doing to remove the Entity:
EntityTransaction t = em.getTransaction();
try {
t.begin();
em.remove(c);
t.commit();
listCountries.remove(c);
} catch (RollbackException e) {
JOptionPane.showMessageDialog(
panelCountries,
"Country already referenced in other Table"
);
}
Mit freundlichen Grüßen / Kind Regards
Christian Reiter
PerCom-Soft HandelsgesmbH
------->> NEU:
Direkte Erreichbarkeit über ENUM und SIP:
ENUM: +43 5242 61177 23
SIP: <sip:52426117723_at_voice.percom.at>
<<-------
--
Christian Reiter
christian@percom.at || http://www.percom.at
fon: +43 5242 61177 || mob: +43 664 924 55 27 || fax: +43 5242 61177 31