Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> setting a default ID with BC4J Entity
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."); }
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
![]() |
![]() |