aceessing 2 tables using one entity bean

Discussions

EJB design: aceessing 2 tables using one entity bean

  1. aceessing 2 tables using one entity bean (4 messages)

    Is it possible to access 2 tables in the backend using only one entitybean? If so how it is possible? plz explain me..Thanx
  2. Are you looking at CMP or BMP? Which App. Server do you want to implement it with? With CMP's in Weblogic, this is not possible. With BMP however you can access more than 1 table.

    Shiva.
  3. Dear Shiva,

         Thanx for that info. I'm looking for BMP in both weblogic and Websphere.explain in detail.

    siddhu.....
  4. aceessing 2 tables using one entity bean[ Go to top ]

    i have a little knowledge in bmp;you can access 2 or more tables in ejbfindby...()method ,but,i want to ask:
    in create()method,it means "insert" operation,how to handle
    more tables in this method.can you give me a example
  5. aceessing 2 tables using one entity bean[ Go to top ]

    BMP is there only for a user to write their own SQL. Inside the BMP you can start your own Transaction and based on your business requirements can write as many SQL's as possible. Here is an example in WebLogic. I don't know how the same works in WebSphere, but the code to most part should remain same as they both follow J2EE arch.

      public String ejbCreate(String a, double b)
        throws CreateException
      {
        this.a = a;
        this.b = b;

        Connection con = null;
        PreparedStatement ps = null;

        try {
          con = getConnection();
          ps = con.prepareStatement("insert into *** (a, b) values (?, ?)");
          ps.setString(1, a);
          ps.setDouble(2, b);
          if (ps.executeUpdate() != 1) {
            String error = "JDBC did not create any row";
            log(error);
            throw new CreateException (error);
          }

          return accountId;
        } catch (SQLException sqe) {
       //do your own processing....
        } finally {
          cleanup(con, ps);
        }
      }