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

Philip Herbst commented on DELTASPIKE-673:
------------------------------------------

Thanks for your quick answers, I will look into the documentation

Btw: Is something like this currently possible? I tried to add a custom 
implementation to my repository but I couldn't get the transaction started 
automatically by the framework (I'm working with Jta and 
org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy). 
The transaction stuff just works on abstract methods (I guess because the 
PartialBean handling isn't invoked in this case). And the Transactional 
annotation just works on non abstract classes...

{code}
@Repository
public abstract class ProductRepository extends 
AbstractEntityRepository<Product, Integer> {

    public void myUpdateImplementationTransactional(Product product) {
        if (product.isTransient()) {
            entityManager().persist(product);
        } else {
            entityManager().merge(product);
        }   
    }
}
{code}

> CdiQueryInvocationContext#isNew does not work well with OpenJpa and detached 
> entities
> -------------------------------------------------------------------------------------
>
>                 Key: DELTASPIKE-673
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-673
>             Project: DeltaSpike
>          Issue Type: Improvement
>          Components: Data-Module
>    Affects Versions: 1.0.0
>            Reporter: Philip Herbst
>            Assignee: Thomas Hug
>
> I'm trying to use org.apache.deltaspike.data.api.EntityRepository on TomEE 
> 1.5.2 with detached entities. Whenever I try to call the save method of 
> EntityRepository I get 
> {code}
> org.apache.openjpa.persistence.EntityExistsException: Attempt to persist 
> detached object
> {code}
> CdiQueryInvocationContex#isNew returns true for my detached entity and and 
> because of that EntityManager#persist is called. 
> see org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler#save
> From OpenJpaPersistenceUtil#getIdentifier(OpenJPAEntityManagerFactory emf,    
>    Object entity)
> {code}
>     /**
>      * Get the object identifier for a persistent entity managed by one
>      * of the entity managers of the specified entity manager factory.
>      * @return The identifier of the entity or null if the entity does
>      * not have an identifier assigned or is not managed by any of the
>      * entity managers of the entity manager factory.
>      */
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to