Thanks Andrus,
it works fine now!
Laila
On Mon, 31 Jan 2005 09:24:07 -0500 (EST), Andrus Adamchik
<andru..bjectstyle.org> wrote:
> Hi Laila,
>
> Yeah, this might be a problem... Here is an easy solution - replace
> "pendingRawNews.setObjectId(key)" with
> "pendingRawNews.getObjectId().setReplacementId(key)"
>
> I guess in the future we need to handle this case somehow on Cayenne end,
> likely by throwing an exception...
>
> Andrus
>
> > Hi Andrus,
> >
> >
> > how you suggest, I read ObjectStore.objectsCommitted and now I'm
> > thinking the problem is in how i create and set the primary key.
> > How to set a new object's id?
> >
> > I report the entire code and the output logger (I have upgraded the
> > cayenne version to Cayenne 1.1)
> >
> > org.objectstyle.cayenne.access.DataContext context;
> > com.extrapola.scooter.dataModel.PendingRawNews pendingRawNews;
> > org.objectstyle.cayenne.ObjectId key;
> > org.objectstyle.cayenne.query.SQLTemplate query;
> > org.objectstyle.cayenne.DataRow dataRow;
> > java.lang.Integer id;
> >
> > context =
> > org.objectstyle.cayenne.access.DataContext.createDataContext();
> >
> > // generate new PK
> > query = new
> > org.objectstyle.cayenne.query.SQLTemplate( com.extrapola.scooter.dataModel.RawNews.class,
> > "SELECT #result('rawnws_seq.nextval'
> > 'java.lang.Integer' 'ID') FROM DUAL",
> > true);
> > query.setFetchingDataRows(true);
> > dataRow =
> > (org.objectstyle.cayenne.DataRow)context.performQuery(query).get(0);
> > id = (java.lang.Integer)dataRow.get("ID");
> >
> > // create a new ObjectId
> > key = new org.objectstyle.cayenne.ObjectId(
> > com.extrapola.scooter.dataModel.PendingRawNews.class,
> > com.extrapola.scooter.dataModel.PendingRawNews.ID_PK_COLUMN,
> > id.intValue());
> >
> > // create and register new object and setting new key
> > pendingRawNews =
> > (com.extrapola.scooter.dataModel.PendingRawNews)context.createAndRegisterNewObject(com.extrapola.scooter.dataModel.PendingRawNews.class);
> > pendingRawNews.setObjectId(key);
> > pendingRawNews.setInsertionDate(new java.util.Date());
> > context.commitChanges();
> >
> > System.out.println("-----------\n" + context.newObjects());
> >
> >
> >
> > INFO 2005-01-31 11:32:27,957 --- will run 1 query.
> > INFO 2005-01-31 11:32:29,653 --- transaction started.
> > INFO 2005-01-31 11:32:30,200 SELECT rawnws_seq.nextval AS ID FROM DUAL
> > INFO 2005-01-31 11:32:30,282 === returned 1 row. - took 81 ms.
> > INFO 2005-01-31 11:32:30,285 +++ transaction committed.
> > DEBUG 2005-01-31 11:32:30,441 Creating InsertBatchQuery for DbEntity
> > PNDRAWNWS INFO 2005-01-31 11:32:30,454 --- transaction started.
> > INFO 2005-01-31 11:32:30,455 --- will run 1 query.
> > INFO 2005-01-31 11:32:30,461 INSERT INTO PNDRAWNWS (ID,
> > INSERTION_DATE) VALUES (?, ?)
> > INFO 2005-01-31 11:32:30,463 [bind: 2066195, '2005-01-31 11:32:30.294']
> > INFO 2005-01-31 11:32:30,473 === updated 1 row.
> > INFO 2005-01-31 11:32:30,476 +++ transaction committed.
> > -----------
> > [{[ insertionDate => Mon Jan 31 11:32:30 CET 2005
> > ]<oid: com.extrapola.scooter.dataModel.PendingRawNews: <ID: 2066195>;
> > state: new>}
> > ]
> >
> > Thanks
> > Laila
>
>
This archive was generated by hypermail 2.0.0 : Mon Jan 31 2005 - 10:29:39 EST