Declarative transaction not working for statteful ejb for 10g AS


EJB programming & troubleshooting: Declarative transaction not working for statteful ejb for 10g AS

  1. Hi Friends,
     While migrating from sun app server to oracle 10g as, i have problem in declarative transactions.
    I created stateless and stateful beans with declarative transactions. Transactions were working fine till they were in sun app server environment, but they fail in oracle 10g as environment.

    I build the ear through sun IDE and deployed the ear on oracle 10g as. Things worked fine till transactions come onto picture.Declarative transaction get failed in case of oracle 10g as.

    Please if you have faced such problem or have any way to solve this problem, Pls revert back.


    Threaded Messages (4)

  2. Message Driven Bean[ Go to top ]


    I ve created a MDB with 3.0 specification.
    The MDB and its client code is given below.

    @MessageDriven(activateConfig =
    @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
    @ActivationConfigProperty(propertyName="destination", propertyValue="queue/STDQ")

    public class HUBMessageBrokerBean implements MessageListener

    public void PostConstruct(){
    System.out.println("Post Construct method is called from MDB");
    public void onMessage(Message arg0) {

    try {
    System.out.println("its coming in MDB bean");
    } catch (Exception e) {



    and the client who calls MDB is as follows:

    public class MDBServlet extends HttpServlet {

        QueueConnectionFactory queueConnectionFactory = null;
        QueueConnection queueConnection = null;
        QueueSession queueSession = null;
        QueueSender queueSender =null;
        Queue queue = null;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    private void addStudent(HttpServletRequest req, HttpServletResponse resp)throws ServletException,IOException {

    try {
    System.out.println("In the MDBServlet engine.");
    ObjectMessage obj = queueSession.createObjectMessage();
    Message msg = queueSession.createMessage();
    // Student_demo student = new Student_demo();
    // student.setFName(req.getParameter("fname"));
    // student.setLName(req.getParameter("lname"));
    String v = "vishal";
    System.out.println("before calling MDB");
    System.out.println("After calling MDB");
    } catch (JMSException e) {
    // TODO Auto-generated catch block
    System.out.println("The exception caught:"+e);

    public void init() throws ServletException {
         try {
         Context context = new InitialContext();
                queueConnectionFactory =
         queueConnection =
         queueSession = queueConnection.createQueueSession(false,
         queue = (Queue)context.lookup("queue/STDQ");
         queueSender = queueSession.createSender(queue);
         } catch (Exception e) {
                System.out.println("Connection problem: " + e.toString());
                if (queueConnection != null) {
                    try {
                    } catch (JMSException ee) {}


    public void destroy() {
            if (queueConnection != null) {
                try {
                } catch (JMSException e) {


    I have also changed or modified jbossmq-service.xml to have the queue name. the entry is as follows:

    <mbean code=""
        <depends optional-attribute-name="DestinationManager"></depends>
        <depends optional-attribute-name="SecurityManager"></depends>

    now the problem is that when my client sends a message to the queue, it should call onMessage() of my MDB but this method is not being called. and also no exception is caught.

    please help me how can i tell the queue or container to call onMessage() of my MDB.

    reply awaited. Thanks.

    Vishal Joshi
  3. Check J2EE specification[ Go to top ]

    If I am not wrong (and I might be), J2EE specification doesn't allow declarative transactions on Stateful Session Beans.
  4. Hi Daniel,
              But Transaction within stateless bean too is not working. Here is the little code i have used for rollback for my stateless bean. stateless bean used context rollback method, but that method doesn't mark my transaction for rollback. This method work only for declarative transactions.


    public String insertRecord(String DAOReference, BonBaseDto insertRecord) throws java.rmi.RemoteException, BONException{
    // Some code for insertion of data.

    }catch(BONException be){
      throw new EJBException("#### BONException: " +
      //throw be;
      catch(Exception e){
      throw new EJBException("#### Exception: " + e.getMessage
      //throw new BONException("BON-SES-INS-ERR-1-01-0001",e);
  5. I guess you should call rollback()[ Go to top ]


    Since you're using bean managed transaction, you're responsible for mark the transaction bondaries.

    So, you have to clearly begin the transaction, and also rollback the transaction. For example :

    Context context = new InitialContext();
    UserTransaction transaction = (UserTransaction) contex.lookup("jta/UserTransaction");

    try {

        // do your database stuff
        // call other beans

    } catch(Exception e) {
       throw e;

    Calling setRollBackOnly() in a bean managed transaction, won't garantee that the transaction will rollback'ed. You have to do that by yourself.