void detach(java.lang.Object entity)
Remove this object from the persistence context , as a result of which the managed object becomes disconnected. Unflushed changes made to the object, if any (including deleting the object), will not be synchronized with the database. Objects that previously referenced a single object will continue to reference it.
void remove(java.lang.Object entity)
Delete an instance of an object. The database is immediately affected.
em.createQuery("DELETE FROM Country").exceuteUpdate();
Whether the deletion is directly in the database, if you have this object, for example, saved in any list or it is a simple reference object, it will not receive these changes and will surely cause an error if it tries to merge or do something with it. Believe me, do not do this if this is your last choice.
Hope this will be a clear answer!
Yours faithfully!
source share