[ 
https://issues.apache.org/jira/browse/DELTASPIKE-871?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14579104#comment-14579104
 ] 

Harald Wellmann commented on DELTASPIKE-871:
--------------------------------------------

There is a frequent misconception about how save(), em.persist() and em.merge() 
really work. Loading an entity, changing its state via setters and then calling 
save() explicitly in the same transaction is an anti-pattern. The effect you 
described may be caused by an inappropriate combination of cascade settings and 
unneeded save() calls.

If you do think the problem is in DeltaSpike and not in your application, then 
please provide a self-contained test case.

> save() and findByxxx() in same transaction gives constraint violation 
> exception
> -------------------------------------------------------------------------------
>
>                 Key: DELTASPIKE-871
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-871
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: Data-Module
>    Affects Versions: 1.2.0
>         Environment: Windows-7, Java-8, Netbeans-8.0.2
>            Reporter: Md Kamaruzzaman
>            Assignee: Daniel Cunha (soro)
>
> It seems like when in the same EJB transaction, save() and findByxxx() is 
> called, then delta-spike inserts the entity twice [once in save() and other 
> time in findByxxx()] and gives a constraint violation exception. 
> After some debuggin, it seems like save() gives a "INSERT" query in DB and 
> findByxxx() method calls a flush which again gives the same "INSERT" query in 
> DB [INSERT query from save() is not removed from EntityManager] and gives 
> constraint violation exception.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to