cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Øyvind Harboe" <oyvind.har...@zylin.com>
Subject Re: UUID as primary key
Date Fri, 21 Jul 2006 21:35:35 GMT
On 7/13/06, Andrus Adamchik <andrus@objectstyle.org> wrote:
>
>
> On Jul 13, 2006, at 12:32 PM, Øyvind Harboe wrote:
>
> > On 7/12/06, Gentry, Michael (Contractor)
> > <michael_gentry@fanniemae.com> wrote:
> >> You could override setPersistenceState() in your Treatment class:
> >>
> >> public void setPersistenceState(int state)
> >> {
> >>   super.setPersistenceState(state);
> >>
> >>   // If object was just created, set PK
> >>   if (state == PersistenceState.NEW)
> >>     setId(UUID.randomUUID());
> >> }
> >
> > Hmmm... I tried that, but setPersistanceState() is invoked multilple
> > times with state=NEW and thus I'm changing the UUID each time. That
> > can't be right.
>
> No it can't - it should only be invoked once per object.


As far as I can tell in the debugger setPersistanceState(state=NEW) is being
invoked multiple times..

First when I create the object and then later on when I commit(there are
child contexts involved, and I first commit to parent, then to the
database):


        if (dataObject.getObjectId() == null) {
            dataObject.setObjectId(new ObjectId(objEntity.getName()));  //
DataContext.registerNewObject(DataObject) line: 920
        }



Treatment(Workaround).setPersistenceState(int) line: 31
DataContext.registerNewObject(DataObject) line: 920
ChildDiffLoader.nodeCreated(Object) line: 110
NodeCreateOperation.apply(GraphChangeHandler) line: 73
CompoundDiff.apply(GraphChangeHandler) line: 133
ObjectStoreGraphDiff.apply(GraphChangeHandler) line: 155
DataContext.onContextFlush(ObjectContext, GraphDiff, boolean) line: 1215
DataContext.onSync(ObjectContext, GraphDiff, int) line: 1194
DataContext.flushToParent(boolean) line: 1261
DataContext.commitChanges() line: 1165
EditTreatment$Enhance_217(EditTreatment).submit(IRequestCycle) line: 142



-- 
Øyvind Harboe
http://www.zylin.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message