cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti with JPA

luisalves00
Champ in-the-making
Champ in-the-making
Hello,

I'm using activiti with JPA.

my config:


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
        <property name="url" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true" />
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="username" value="activiti" />
        <property name="password" value="activiti" />
        <property name="defaultAutoCommit" value="false" />

         <!– confirm these properties –>
        <!– <property name="jdbcMaxActiveConnections" value="300" />
        <property name="jdbcMaxIdleConnections" value="30" /> –>
    </bean>

    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />

        <property name="databaseType" value="mysql" />
        <property name="databaseSchemaUpdate" value="true" />

        <property name="jpaPersistenceUnitName" value="GAEPU" />
        <property name="jpaHandleTransaction" value="true" />
        <property name="jpaCloseEntityManager" value="true" />


        <property name="history" value="audit" />
    </bean>


Issue:

    When I set new values on the (JavaDelegate) service task they don't seem to be "auto-magically" updated.

Tried to invoke this code at the end:

private void updatePedidoAutorizacao(PedidoAutorizacao pa) throws Exception {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        PedidoAutorizacaoJpaController authorizationRequestController = (PedidoAutorizacaoJpaController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "PedidoAutorizacaoJpa");
        authorizationRequestController.edit(pa);
    }

but get some weird behaviour, i.e. tries to insert stuff that is already there and got an exception:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'SomeCo' for key 'designacao'
4 REPLIES 4

luisalves00
Champ in-the-making
Champ in-the-making
well…seems like it's updating some stuff…

PedidoAutorizacao pa = (PedidoAutorizacao) execution.getVariable("authRequest");

pa.setEnviadoPortaria(false);
pa.setEnviadoProgramador(false);

^ those are updated….


Questions?

1.

if its an entity (EstadoPedidoAutorizacao jpa entity) will this work:


if (pa.getEnviadoPortaria()) {
                pa.setEstadoPedidoAutorizacao(estadoPedidoAutorizacaoJpa.findEstadoPedidoAutorizacao(AuthorizatonRequestStatus.ENVIADO_PORTARIA.getId()));

2. on a userTask is possible to update?
   reading the doc…seems like I need a variable to store the userTask decision and a service task to update the model.

luisalves00
Champ in-the-making
Champ in-the-making
pa.setEstadoPedidoAutorizacao(estadoPedidoAutorizacaoJpa.findEstadoPedidoAutorizacao(AuthorizatonRequestStatus.ENVIADO_PORTARIA.getId()));
Activiti inserts new records on my db…any idea why?

EstadoPedidoAutorizacao entity comes from the DB and already has an ID…Activiti creates a new one…

jbarrez
Star Contributor
Star Contributor
Is it possible to simplify the examples, I'm having a hard time understanding due to my lack of Spanish(?)

If you have set an JPA entity as process variable, Activiti will use the entity mgr you defined in your config for reading and updating.
So it's very strange that you see an insert with a new id!

luisalves00
Champ in-the-making
Champ in-the-making
Well…I quit using "your" JPA feature. Doing the hard work myself. And it's Portuguese not Spanish (you're close).

tks