如何在EJB中执行XA事务?
我有一个 MDB 正在监听特定主题。
我已经使用 jboss 配置了 XA 数据源...
我已经设置了持久性 .xml
<persistence-unit name="jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jdbc/BKS_DataSource</jta-data-source>
<class>com.jms.mdb.SampleData</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<!--
<property name="hibernate.format_sql" value="true"/>
-->
</properties>
</persistence-unit>
每当我收到一些东西时,我只是在 MDB 中执行此代码
@PersistenceContext
EntityManager em = null;
public void onMessage(Message message) {
try {
LoggingEvent event = (LoggingEvent)((ObjectMessage)message).getObject();
System.out.println("Received something11");
SampleData s= new SampleData();
s.setMessage(event.getLoggerName());
em.persist(s);
System.out.println("Persisted");
//Create.main(null);
} catch (JMSException e) {
e.printStackTrace();
}
}
所以基本上我需要执行两阶段提交事务...所以我想知道我应该做什么必须执行 XA 事务......另外我只想在 Java EE 5 上执行此操作
I have a MDB listening to particular topic.
I have configured XA data source with jboss...
I have set persistance .xml
<persistence-unit name="jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jdbc/BKS_DataSource</jta-data-source>
<class>com.jms.mdb.SampleData</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<!--
<property name="hibernate.format_sql" value="true"/>
-->
</properties>
</persistence-unit>
And whenever I receive something I just execute this code in MDB
@PersistenceContext
EntityManager em = null;
public void onMessage(Message message) {
try {
LoggingEvent event = (LoggingEvent)((ObjectMessage)message).getObject();
System.out.println("Received something11");
SampleData s= new SampleData();
s.setMessage(event.getLoggerName());
em.persist(s);
System.out.println("Persisted");
//Create.main(null);
} catch (JMSException e) {
e.printStackTrace();
}
}
So basically I need to perform Two phase commit transaction...So I want to know what should I have to do perform XA transaction....Plus I want to do it only on Java EE 5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的数据源配置为 XA 数据源,那么您所需要做的就是使用适当的事务管理注释来注释您的 MDB:
If your data source is configured to be an XA data source, then all you need to do is to annotate your MDB with the appropriate transaction management annotations: