0 Replies Latest reply on Jul 25, 2013 2:18 AM by Ben Gao

    javax.jms.JMSException: Could not create a session: Could not enlist in transaction on entering meta-aware object!

    Ben Gao Novice

      sometimes will error.I think it may my code error:

      my class:

      @Stateless(mappedName = "SyncCommonParameterService", name = "SyncCommonParameterService")

      @Remote(SyncCommonParameterService.class)

      public class SyncCommonParameterServiceBean implements SyncCommonParameterService{

       

       

                private Logger log = Logger.getLogger(SyncCommonParameterServiceBean.class);

       

       

                /*JMS连接*/

                private QueueConnection jmsConnection;

       

                private QueueConnectionFactory cf;

       

       

                //JMS队列

                private Queue queue;

       

       

                //JMS目的地JNDI名称

                static final String QUEUE_NAME = "/queue/paraQueue";

       

                @PostConstruct

                public void init() {

                          InitialContext ic = null;

                          try {

                                    ic = new InitialContext();

                                    /** 查找消息队列连接静态工厂*/

                        cf = (QueueConnectionFactory) ic.lookup("java:JmsXA");

                         

                          } catch (Exception e) {

                                    log.error("get jms ConnntectionFactory Error");

                          }

                          try {

                                    // 查找消息队列

                                    queue = (Queue) ic.lookup(QUEUE_NAME);

                          } catch (Exception ex) {

                                    log.error("Looking up Activation Queue failed.", ex);

                          }

       

       

       

                }

       

                /**

                 * 发送公参同步请求<br>

                 * @param paraCode - 公参类型

                 * @param batchNo - 批次号

                 * @param pubSyncType - 0 正常同步

                 * @param userId - 用户标识

                 */

                public String doSync(String paraCode, String batchNo){

                          //返回 0 成功; 1 失败

                          String result = "1";

                          QueueSender sender = null;

                          QueueSession session = null;

                          try {

                                    log.info("********* paraCode: [" + paraCode + "], batchNo: [" + batchNo + "] ************");

                                    if(paraCode==null || paraCode.trim().length()==0){

                                              return result;

                                    }

                                    if(batchNo==null || batchNo.trim().length()==0){

                                              return result;

                                    }

                                    log.debug("Sending message to online central MDB...");

       

                                    jmsConnection = cf.createQueueConnection();

       

       

                                    // 创建消息连接会话对象

                                    session = jmsConnection.createQueueSession(false, //non transacted

                                                        Session.AUTO_ACKNOWLEDGE);

                                    // 创建消息发送者

                                    sender = session.createSender(queue);

       

       

                                    // 创建消息对象

                                    ObjectMessage message = session.createObjectMessage();

       

                                    message.setStringProperty(CommonConstants.JMS_TRANS_TYPE, CommonConstants.JMS_EVENT_TYPE_PARAMETER_COMMON);

                                    WTCMessageObject mo = new WTCMessageObject();

                                    mo.setBatchNo(batchNo.trim());

                                    mo.setParaType(paraCode.trim());

                                    message.setObject(mo);

       

       

                                    // 发送JMS消息

                                    sender.send(message);

       

       

                                    log.debug("sync pub para message sent OK.");

       

                                    result = "0";

                          } catch (Exception ex) {

                                    log.error("sync pub para message send error", ex);

                                    result = "1";

                          } finally{

                                    // 停止消息连接对象

                                    if(sender!=null){

                                              try{

                                                        sender.close();

                                              }catch(Exception e){

                                                        log.error("close sender error", e);

                                              }

                                    }

                                    if(session!=null){

                                              try{

                                                        session.close();

                                              }catch(Exception e){

                                                        log.error("close session error", e);

                                              }

                                    }

       

       

                          }

                          return result;

                }

       

      }

       

      log:

      javax.jms.JMSException: Could not create a session: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: -53ee06fc:896a:51f0b3f2:12ee status: ActionStatus.ABORT_ONLY >)

              at org.hornetq.ra.HornetQRASessionFactoryImpl.allocateConnection(HornetQRASessionFactoryImpl.java:881)

              at org.hornetq.ra.HornetQRASessionFactoryImpl.createQueueSession(HornetQRASessionFactoryImpl.java:237)

              at com.cup.chmgm.etl.SyncCommonParameterServiceBean.doSync(SyncCommonParameterServiceBean.java:108)

              at sun.reflect.GeneratedMethodAccessor396.invoke(Unknown Source)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)

              at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72)

              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)

              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)

              at sun.reflect.GeneratedMethodAccessor320.invoke(Unknown Source)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)

              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)