Mule JPA persist is not inserting or updating

前端 未结 2 493
面向向阳花
面向向阳花 2021-01-25 04:38

I am using Mule JPA module for retrieving and insert/updating data. I can able retrieve data but not able to update the DB. Its giving no errors and as per the log it seems that

相关标签:
2条回答
  • 2021-01-25 05:01

    Finally could able to commit transaction using MULE JPA transport, by creating CustomTransactionFactory which starts the transaction.

    public class CustomTransactionFactory implements TransactionFactory{
    
    @Override
    public Transaction beginTransaction(MuleContext muleContext)
            throws TransactionException {
        EntityManagerFactory emf = muleContext.getRegistry().lookupObject("entityManagerFactory");
        TransactionFactory tf = new JPATransactionFactory();
    
        Transaction tx = tf.beginTransaction(muleContext);
        tx.bindResource(emf, emf.createEntityManager());
        tx.begin();
        return tx;
    }
    
    @Override
    public boolean isTransacted() {
        return true;
    }
    

    }

    By referring custom transaction manager in In-bound endpoint as below, we can achieve flow level transactions.

     <flow name="jpa_exampleFlow1" doc:name="jpa_exampleFlow1">
        <http:inbound-endpoint exchange-pattern="request-response"   doc:name="HTTP" address="http://localhost:9090/jpa_example">
        <custom-transaction action="ALWAYS_BEGIN" factory-ref="transctionManager"/>
    

    Note: Transactional blocks are no more required.

    0 讨论(0)
  • 2021-01-25 05:02

    Here your console shows :- Hibernate: insert into contact (EMAIL, FIRSTNAME, LASTNAME) values (?, ?, ?) and your payload is :- {"firstName":"king","lastName":"verma","email":"vermaS@xxx.com","id":9} ... where this id:"9" will be accommodated ? your query has 3 fields firstname,lastname and email ..where as your payload contains firstname,lastname,email and id

    0 讨论(0)
提交回复
热议问题