You can't use identity columns with EJBs as a primary keys if you use create
method, you have to set primary key property during the call of create
method.However, in this mailing list I saw ingenious hack to use finder
method as a replacement of create.So basicly you never call create method
but this finder instead.It looked something like :
INSERT INTO sometable (filed1,field2) VALUES ($field1,$field2);
SELECT pk_identity_column,field1,field2 from sometable where
pk_identity_column=@@IDENTITY
Obviously it will not work with other application servers that have it's own
language for defining queries (WebLogic for example).
Boris.
P.S. Consider it as a workaround if you absolutely must use identities and
NOT as a good programming practice that you should follow.
----- Original Message -----
From: "fresnaULL" <[EMAIL PROTECTED]>
To: "Orion-Interest" <[EMAIL PROTECTED]>
Sent: Wednesday, November 29, 2000 9:52 AM
Subject: Problems with an identity (autoincrement) field.
> Hi,
> I've made an entity cmp which map a database table which has an
> identitiy (autoincrement) field as primary key.
> When I do a home.create(primary_key) I get the following error:
>
> [Microsoft][ODBC SQL Server Driver][SQL Server] Cannot insert explicit
> value for identity column in table when IDENTITY_INSERT is set to OFF.
>
> I've been looking for the INSERT statement which i guess is asociated with
> the create method to try to fix it up but I haven't found it.
>
> Does anybody know what I have to do?
>
> Thanks in advance.
>
>
>
>