0 Replies Latest reply on Jan 11, 2005 8:12 PM by Hany Bee

    Weird Oracle9i and ejbCreate()/ejbPostCreate() problems

    Hany Bee Newbie


      I'm having this weird problem that I'm not quite sure how to deal with.

      I have a table TestMe:

      id varchar(32)
      name varchar(32)
      type varchar(10)
      parent varchar(32)

      The column "parent" is actually the same as the "id", an object can have sub-objects. And "parent" can be null, if the object is the root node.

      And I have a uniqueness constraints for the 3 columns: name, type, parent. And a primary key on row id.

      Now, in my entity bean methods:
      public Object ejbCreate(String name, String type, MyBeanLocal parent)
      public void ejbPostCreate(String name, String type, MyBeanLocal parent)
      public abstract String getName();
      public abstract void setName(String name);
      public abstract void setType(String type);
      public abstract void setParent(MyBeanLocal parent);
      public String getID()
       return ctx.getPrimaryKey().toString();

      This works fine with PostgreSQL, but Oracle9i is giving me funny unique constraint violation error.

      If I have two root nodes A and B like this:
       A -> B -> C

      A has a child node B, which has another child node C. The second B is a second root node.

      Assuming that the type of all nodes is the same, now if I add a child node called C under the root node B, this should not be a problem, as the parent of the new node is B, which has a different ID than the child node B of A.

      And this works fine in PostgreSQL (7.4, and 8.0Beta2). In Oracle9i, it's giving me the unique constraint violation error.

      I debug into the code, and found really weird behavior. I got the error after the ejbCreate() method, and before I got a chance to get into the ejbPostCreate() method.

      This is obviously a problem, because before I got a chance to set the parent in ejbPostCreate(), the parent column is null, and Oracle seems to compare only two other columns (name and type) and ignore the parent column, and that violates the unique constraint.

      What I don't understand is that, how an the app server persistence manager allows this kind of thing happen? Aren't the methods ejbCreate() and ejbPostCreate() supposed to complete consistently? And I can't invoke the method setParent() directly from ejbCreate() because that would violate the EJB 2.0 specs for CMR field.

      Any idea how I can solve this problem? I'm using the Oracle9i thin driver.

      Thanks a lot.