From: Gavin K. <ga...@ap...> - 2002-09-27 16:33:55
|
> Would implementing ClassPersister be the way to go for this? At first > (and uninformed) glance it would seems like all I'd need to do is > override insert() from EntityPersister and instead of setting the ID to > the IDENTITY value returned, set a particular field in the ID to the > IDENTITY value returned. Well, almost. Might be a little bit of extra fiddling because there are two versions of insert: (1) take an id and return nothing (2) take just the fields and return an id (meant for use with IDENTITY columns) You *have* to use version (2) because that version is called immediately from save() rather than buffered for later. To make sure (2) gets called you need to: * override getIdentifierGenerator() to return an instance of NativeGenerator (because its always Assigned for composite id classes) * override isIdentifierAssignedByInsert() to return true * Override insert() as you described. Return the id from this method. Oh, a couple more things: * EntityPersister is currently declared final and I will probably leave it that way so use delegation, not inheritence * I need to wire in a little bit of code to allow the mapping document to specify a ClassPersister implementation class (I'll do that tomorrow) * I changed the ClassPersister interface earlier today to generalize it a bit. Grab a CVS update. Gavin > > > Hold on.....somethings not right.....the IDENTITY column has to be unique of > > its own accord, right? > > Yes, but for various reasons the IDENTITY field is not the only field in > the key. The joys of retrofitting :-) So MS SQL can generate |