Mybatis with ejb on jboss 6

23 views
Skip to first unread message

Mauricio Amorim Da Silva

unread,
May 21, 2019, 5:46:47 PM5/21/19
to mybatis-user
Hi mybatis users...

I was trying use mybatis with ejb on jboss 6.

when i call a RequiresNew session bean method it's not commited after the methods finish.

someone already had the same problem ? thank you

Example:

----------------

ResubmissionServiceFactory.getResubmissionService().updateResubmissionsRequiresNew(
        ResubmissionTO.EXECUTING, ResubmissionBuilder.transform(invoicesToUpdateStatus), new Date());

-> here the data is not comited

----------------------------

/**
* @ejb.interface-method
* @ejb.transaction type="RequiresNew"
*/
@Override
public void updateResubmissionsRequiresNew(Integer state, Collection<ResubmissionTO> resubmissions,
        Date processDate) {
ResubmissionDAO.getInstance().updateResubmissions(state, resubmissions, processDate);
}


ResubmissionDAO:

@Override
public void updateResubmissions(Integer state, Collection<ResubmissionTO> resubmissions, Date processDate) {
SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession(ExecutorType.BATCH);
try {
ResubmissionMapper mapper = sqlSession.getMapper(ResubmissionMapper.class);
for (ResubmissionTO resubmissionTO : resubmissions) {
mapper.updateStateErrorResubmission(resubmissionTO.getId(), state, resubmissionTO.getErrorMessage(),
        processDate, resubmissionTO.getLotEventId());
}
sqlSession.flushStatements();
sqlSession.commit();
} finally {
sqlSession.close();
}
}

Guy Rouillier

unread,
May 22, 2019, 2:06:00 AM5/22/19
to mybati...@googlegroups.com
See the MyBatis User Guide.  flushStatements is defined like this:

List<BatchResult> flushStatements()

Have you iterated over the List<BatchResult> to see the outcome of your statements?  I do not see that in the code below, so this code seems to assume that everything completes successfully.  Also, the default configuration for JBoss connections is they handle commits themselves.  I'm assuming you are using the JBoss connection pool.  Lots of assumptions here.  If you are using the JBoss connection pool, and the JBoss transaction manager, then you are not expected to issue your own commits.  Are you checking the JBoss logs to ensure the code is not generating errors?

--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/e8bca5c9-9648-4400-9577-d98fff006435%40googlegroups.com.

Mauricio Amorim Da Silva

unread,
May 22, 2019, 8:47:04 AM5/22/19
to mybatis-user
HI Guy Rouillier,

I was using jboss 6 connection pool and jboss transaction manager. 
My mybatis configurration is:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
<configuration>
  <typeAliases>
<typeAlias alias="resubmission" type="com.cpqd.billing.collection.model.event.ResubmissionTO"/>
  </typeAliases>  
  
  <environments default="development">
    <environment id="development">
<transactionManager type="MANAGED" />
<dataSource type="JNDI">
<property name ="data_source" value="java:/CBILLDS"/>
</dataSource>   
    </environment>
  </environments>
  
  <mappers>
    <mapper resource="com/cpqd/billing/collection/model/myibatis/collection-model-myibatis-resubmission-mapper.xml"/>
  </mappers>
</configuration>

I try remove the line sqlSession.commit() but the update is not commited on oracle database  

I did the same using old ibatis version and the updates are commited.

My old ibatis config is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sql-map-config
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 1.0//EN"

<!-- Always ensure to use the correct XML header as above! -->

<sql-map-config>

    <settings useGlobalTransactions="true"/>

    <sql-map resource="com/cpqd/billing/collection/model/ibatis/CollectionModel.xml" />

</sql-map-config>

Do you know if this line:

    <settings useGlobalTransactions="true"/>

has similar configuration on mybatis ?

Thank you.



To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.

Mauricio Amorim Da Silva

unread,
May 23, 2019, 9:07:03 PM5/23/19
to mybatis-user
HI Guy Rouillier,

did you know if exists any difference between ejb2 and ejb3 transactions intercept on jboss that can caused this behavior?

thank you


Em quarta-feira, 22 de maio de 2019 03:06:00 UTC-3, Guy Rouillier escreveu:
To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.

Mauricio Amorim Da Silva

unread,
Jun 11, 2019, 4:35:17 PM6/11/19
to mybatis-user
Hi people of mybatis forum,

I tried newly using mybatis with jboss 6 and i use RequiresNew ejb methods running very well.

Thank you for the Help.

Follow configuration files and java files:

  <environments default="development">
    <environment id="development">
<transactionManager type="MANAGED"/>
<dataSource type="JNDI">
<property name ="data_source" value="java:/CBILLDS"/>
</dataSource>   
    </environment>
  </environments>


SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession(ExecutorType.BATCH);
try {
ResubmissionMapper mapper = sqlSession.getMapper(ResubmissionMapper.class);
for (ResubmissionTO resubmissionTO : resubmissions) {
mapper.updateStateResubmission(resubmissionTO.getId(), resubmissionTO.getState(),
        resubmissionTO.getLotEventId(), resubmissionTO.getProcessDate());
}
} finally {
sqlSession.flushStatements();
sqlSession.close();
}
Reply all
Reply to author
Forward
0 new messages