AnsweredAssumed Answered

Mail Service taks using expression to evaluate To field

Question asked by anantesh on Aug 4, 2012
I am facing a hard time in sending mail to all the group members dynamically based on an event.

${mailingGroupService.findEventSubscribersMailIdByAlertEvent("EventA")}

The code for my method is:
     
      StringBuffer subscribersEmailId = new StringBuffer();
      //name of the event which has occurred;
      List<MailEventSubscription>  subs = mailEventSubscriptionService.findMailEventByAlertEvent(event);
     
      for(MailEventSubscription sub:subs)
      {
        List<User> users = identityService.createUserQuery().memberOfGroup(sub.getSubscribedGroupId()).list();
        for(User usr:users)
        {
          subscribersEmailId.append(usr.getEmail());
          subscribersEmailId.append(",");
        }       
      }     
     
        return subscribersEmailId.toString();

My spring bean is called correctly and returns a comma separated list of email-ids. The groups in MailSubscription table are the same as the Group Key in ACT_ID_GROUP without any FK references.


Once an email has been sent, an exception is thrown

2012-08-04 16:05:01,304 DEBUG SQL::logStatement > select mailevents0_.maileventsubscriptionid as maileven1_13_, mailevents0_.createdtimestamp as createdt2_13_, mailevents0_.updatedtimestamp as updatedt3_13_, mailevents0_.mailEvent_maileventid as mailEvent5_13_, mailevents0_.subscribedGroupId as subscrib4_13_ from mk_maileventsubscriptions mailevents0_ where mailevents0_.mailEvent_maileventid=? (Client#1-1)

2012-08-04 16:05:01,310 DEBUG Loader::doQuery > Result set row: 0 (Client#1-1)

2012-08-04 16:05:01,312 DEBUG Loader::getRow > Result row: EntityKey[com.model.MailEventSubscription#5] (Client#1-1)

2012-08-04 16:05:01,314 DEBUG TwoPhaseLoad::doInitializeEntity > Resolving associations for [com.markit.ims.model.MailEventSubscription#5] (Client#1-1)

2012-08-04 16:05:01,316 DEBUG TwoPhaseLoad::doInitializeEntity > Done materializing entity [com.markit.ims.model.MailEventSubscription#5] (Client#1-1)

2012-08-04 16:05:01,318 DEBUG StatefulPersistenceContext::initializeNonLazyCollections > Initializing non-lazy collections (Client#1-1)

2012-08-04 16:05:04,884 DEBUG JpaTransactionManager::doGetTransaction > Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@79b80e60] for JPA transaction (Client#1-1)

2012-08-04 16:05:04,886 DEBUG JpaTransactionManager::handleExistingTransaction > Participating in existing transaction (Client#1-1)

2012-08-04 16:05:04,890 DEBUG JpaTransactionManager::doGetTransaction > Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@79b80e60] for JPA transaction (Client#1-1)

2012-08-04 16:05:04,891 DEBUG JpaTransactionManager::handleExistingTransaction > Participating in existing transaction (Client#1-1)

2012-08-04 16:05:04,893 DEBUG Connection::debug > ooo Connection Opened (Client#1-1)

2012-08-04 16:05:04,924 DEBUG SQL::logStatement > select U.*
    
    from ACT_ID_USER U
    
      inner join ACT_ID_MEMBERSHIP M on U.ID_ = M.USER_ID_
      inner join ACT_ID_GROUP G on M.GROUP_ID_ = G.ID_
    
     WHERE  G.ID_ = ? (Client#1-1)

2012-08-04 16:05:04,926 DEBUG PreparedStatement::debug > ==>  Executing: select U.* from ACT_ID_USER U inner join ACT_ID_MEMBERSHIP M on U.ID_ = M.USER_ID_ inner join ACT_ID_GROUP G on M.GROUP_ID_ = G.ID_ WHERE G.ID_ = ?  (Client#1-1)
2012-08-04 16:05:04,928 DEBUG PreparedStatement::debug > ==> Parameters: analyst(String) (Client#1-1)
2012-08-04 16:05:04,937 DEBUG ResultSet::debug > <==    Columns: ID_, REV_, FIRST_, LAST_, EMAIL_, PWD_, PICTURE_ID_ (Client#1-1)
2012-08-04 16:05:04,939 DEBUG ResultSet::debug > <==        Row: abc@xyz.com, 1, Abc, Xyz, abc@xyz.com, null, null (Client#1-1)
2012-08-04 16:05:04,947 DEBUG Connection::debug > xxx Connection Closed (Client#1-1)
2012-08-04 16:05:18,196 ERROR Connection::error > Error calling Connection.prepareStatement: (Client#1-1)

org.hibernate.HibernateException: proxy handle is no longer valid
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.errorIfInvalid(AbstractProxyHandler.java:63)
   at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:122)
   at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
   at $Proxy32.prepareStatement(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:229)
   at $Proxy30.prepareStatement(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)

I have configured JpaTransactionManager. Below is context xml file:

    <tx:annotation-driven />    
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <qualifier value="txManager1"/>
    </bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="IMSJPA" />
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
        </property>
        <property name="dataSource" ref="dataSource" />       
        <property name="jpaVendorAdapter">
            <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="${hibernate.show_sql}" />               
                <property name="database" value="${hibernate.database}" />
            </bean>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
                <property name="driverClass" value="${hibernate.connection.driver_class}" />
                <property name="url" value="${hibernate.connection.url}" />
                <property name="username" value="${hibernate.connection.username}" />
                <property name="password" value="${hibernate.connection.password}" />
    </bean>

    <bean id="activtiDataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        <property name="targetDataSource" ref="dataSource" />
    </bean>

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="databaseType" value="oracle" />
        <property name="dataSource" ref="activtiDataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="false" />
        <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
        <property name="jpaHandleTransaction" value="true" />
        <property name="jpaCloseEntityManager" value="true" />
        <property name="jobExecutorActivate" value="false" />
        <property name="deploymentResources" value="classpath*:/process/GenericProcess.bpmn20.xml" />
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />       
    </bean>
    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
    <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />

Someone please help?

Outcomes