我采用的容器管理事务,em和emM是两个不同的数据源,不过已经写在xa的配置里了。我想让容器来管理分布式的事务,可以吗?该怎么做?
以下是我写的例子,执行到emM那边就不行了。
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ClientAuditSessionBeanImpl extends BaseSessionBeanImpl implements
IClientAuditSessionBeanRemote, IClientAuditSessionBeanLocal
{
@PersistenceContext(unitName = "PostgresDS")
protected EntityManager em;
@PersistenceContext(unitName = "MySqlDSDuan")
protected EntityManager emM;
/
* 客户端鉴权
*
* @param clientAuthenticationREQ 客户端参数bean
*/
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public ResponseBean clientAudit(
ClientAuthenticationREQ clientAuthenticationREQ)
{
try
{
em.createQuery();//em的操作
dd();
String dd = "dd";
Integer.parseInt(dd);
}
catch (Exception e)
{
logger.error("[" + this.getClass().getSimpleName() + "] "
+ e.getMessage(), e);
/
* 为了使容器能获取到异常 从而自动回滚
*/
throw new RuntimeException();
}
return rb;
}
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void dd()
{
Query d = emM
.createNativeQuery(" insert into tbl_dish (dish_name,dish_price) values ('ddddd','dddd') ");
d.executeUpdate();
}
}
这个代码执行到d.executeUpdate();就报错了,不知道问题在哪里
请大家帮忙找下原因,谢谢