This content has been marked as final. Show 2 replies
This is expected behavior as persist is a no-op if called on a managed entity (other than to cascade over relationships marked with cascade.Persist), and the first persist call makes the passed in team entity managed.
Try calling em.flush(); and em.clear(); between the persist calls to get an exception.
The first flush will ensure the team is inserted in the database, while clear will detach it so that the second persist call will try to insert the team. JPA providers are not required to throw the entityExistsException on persist - it can be delayed until the transaction is flushed or committed, so you are likely to get a PersistenceException from the commit instead of EntityExistsException from persist.
Thank you so much!!!
The behaviour is exactly as you predicted. persist is a no-op operation if it applies to a managed entity. It is clear (the worst thing is that I knew it!!!!). Thank you very very much again.!!!!