Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> setting a default ID with BC4J Entity

setting a default ID with BC4J Entity

From: Owen Gibbins <oweng_at_autoplan.ws>
Date: Wed, 13 Nov 2002 11:36:43 -0800
Message-ID: <2TxA9.190661$C8.483804@nnrp1.uunet.ca>


Hello all,

I'm trying to customize an Entity object in order to set the ID column of a newly created row to a unique number. I'm overriding the create method of the object. I managed to get it to work using the following:

  protected void create(AttributeList nameValuePair)
{

    super.create(nameValuePair);
    final String stmt = "SELECT MAX(ID) + 1 FROM PRODUCER";     Number id = new Number(0);
    ViewObject idView =
getDBTransaction().createViewObjectFromQueryStmt(stmt);

    Row idRow = idView.next();
    if(idRow != null)
    {

      Object o = idRow.getAttribute(0);
      if(o != null)
      {
        if(o instanceof Number)
          id = (Number)o;
        else
          throw new Error("ProducerImpl.create: \"" + stmt + "\" did not
produce type NUMBER.");
      }

    }
    setID(id);
  }

The problem with this is that the SELECT statement only considers rows that have been posted to the database. I need the other newly created rows in the current transaction to be considered as well. So I tried the following:

  protected void create(AttributeList nameValuePair)
{

    super.create(nameValuePair);
    ViewObject view = getDBTransaction().createViewObject("ProducerView");     view.setOrderByClause("ID DESC");
    view.executeQuery();
    Number id;
    ProducerViewRow row = (ProducerViewRow)view.next();     if(row != null)
      id = row.getID();
    else
      id = new Number(0);
    setID(id);
  }

The createViewObject() throws an exception. So I suppose my question is: how do I create a view object from within an Entity method?

Thanks for any help!

Owen Received on Wed Nov 13 2002 - 13:36:43 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US