5 Replies Latest reply on Sep 24, 2004 2:16 AM by Gianluca Chini

    Strange behaviour

    Gianluca Chini Newbie

      Hi,
      I have a method in a session bean in wich an entity bean is created.
      In the same method, after the creation i call a finder on that entity Home and the result is correct.

      For performance reasons I have changed the finder with a SQL command looking up the DataSource, but the entity created is not in the result set.

      It seems that the SQL command runs in another transaction, but the transaction attribute for all the beans involved is set to Required.

      Recently we have migrated to Jboss 3.2.5.
      The same method works fine with jboss 3.0.4

      Thanks

        • 1. Re: Strange behaviour
          Alexey Loubyansky Master

          Are you accessing exactly the same DataSource used by the entity beans?

          • 2. Re: Strange behaviour
            Gianluca Chini Newbie

            Yes,
            the datasource is the same...
            With jboss 3.0.4 it works fine, but not with 3.2.5

            Thanks

            • 3. Re: Strange behaviour
              Alexey Loubyansky Master

              You should to provide a testcase as it works for me:
              log.debug("RUN>");

              CLocal c = CUtil.getLocalHome().create(new Long(1));

              DataSource ds = (DataSource)new InitialContext().lookup("java:/DefaultDS");
              Connection con = null;
              PreparedStatement st = null;
              ResultSet rs = null;
              try
              {
              con = ds.getConnection();
              final String sql = "select * from c where id=?";
              log.debug("executing: " + sql);
              st = con.prepareStatement(sql);
              st.setInt(1, 1);
              rs = st.executeQuery();

              if(rs.next())
              {
              log.debug("FOUND");
              }
              else
              {
              log.debug("NOT FOUND");
              }
              }
              finally
              {
              JDBCUtil.safeClose(rs);
              JDBCUtil.safeClose(st);
              JDBCUtil.safeClose(con);
              }

              log.debug("RUN> done in " + (System.currentTimeMillis() - startTime) + " ms.");


              10:49:20,128 DEBUG [FacadeSessionBean] RUN>
              10:49:20,148 DEBUG [C] Executing SQL: SELECT COUNT(*) FROM C WHERE id=?
              10:49:20,158 DEBUG [C] Executing SQL: INSERT INTO C (id, firstName, lastName, a_id) VALUES (?, ?, ?, ?)
              10:49:20,178 DEBUG [FacadeSessionBean] executing: select * from c where id=?
              10:49:20,178 DEBUG [FacadeSessionBean] FOUND
              10:49:20,178 DEBUG [FacadeSessionBean] RUN> done in 50 ms.

              • 4. Re: Strange behaviour
                Gianluca Chini Newbie

                My scenario si more complex..

                The query command (and the datasource lookup) is made by another EJB Stateful ( it serves in other cases to paginate the results ).
                I create this ejb (the create method makes the query) and then I call a getAll method wich returns all the data retrieved by the query.


                Thanks.

                • 5. Re: Strange behaviour
                  Gianluca Chini Newbie

                  May be it is a commit option setting??