The solution looks nice, but the fact that it works may be purely
coincidental :-)
ObjectIds are used as keys to lookup objects in the DataContext, so
manually replacing the id may have undesired and unpredictable
consequences (now or in the future). I would do something like this
instead, that's a bit safer, but is not really tested either, so use at
your own risk (and report any problems you find :-)) :
DataObject object = context.createAndRegister...
ObjectId id = new ObjectId(object.getClass(),
object.class.COD_USER_PK_COLUMN, 500);
// this is presumably safer...
object.getObjectId().setReplacementId(id);
...
context.commitChanges();
Andrus
On Jun 25, 2004, at 3:05 PM, SP Reinaldo Sartorelli - Anal. Programador
wrote:
> tks for your help and iīve found another solution.
>
> What do you think about it?
>
> ObjectId id = new ObjectId(class.getClass(),
> class.COD_USER_PK_COLUMN, 500);
> System.out.println("OID - <GENERATED>: " + id.toString()); //
> = 500
> class.setObjectId(id);
> class.setLoginUsuer("REINALDO");
> class.setNomeUser("REINALDO COELHO");
> context.commitChanges();
> System.out.println("OID - <GENERATED>: " +
> class.getObjectId().toString());
>
> Reinaldo.
>
> -----Mensagem original-----
> De: Andrus Adamchik [mailto:andru..bjectstyle.org]
> Enviada em: sexta-feira, 25 de junho de 2004 15:41
> Para: cayenne-use..bjectstyle.org
> Assunto: Re: Help...
>
>
>
> Hi there,
>
> If your table has a meaningful PK, you can just map it as an object
> attribute and set it via setXYZ() method on a DataObject.
>
> On automated reverse-engineering CayenneModeler skips all PK columns
> and doesn't add them to the object model, however it is very easy to
> add a new ObjAttribute and map it to "CODUSER" column. Use this button
> - http://objectstyle.org/cayenne/images/modeler/icon-attribute.gif :-)
>
> Cheers,
> Andrus
>
>
>
> On Jun 25, 2004, at 11:05 AM, SP Reinaldo Sartorelli - Anal.
> Programador wrote:
> > All, iīve a problem to add a row in the database, iīve a table :
> >
> > USER <TABLE>(
> > PK CODUSER
> > NOMUSER
> > LOGUSER
> > );
> >
> > and i donīt know add a new ObjectId, and a CODUSER is not
> > auto-increment.
> >
> > I using a SQL server 6.5
> >
> > Tks.
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.665 / Virus Database: 428 - Release Date: 21/4/2004
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.665 / Virus Database: 428 - Release Date: 21/4/2004
>
This archive was generated by hypermail 2.0.0 : Fri Jun 25 2004 - 15:25:09 EDT