Primary Key issues

Posts   
 
    
Emerald
User
Posts: 5
Joined: 01-Aug-2006
# Posted on: 26-Oct-2006 20:05:52   

I am using adapter in the latest version of LLBL gen Pro along with .NET 2.0, VS.NET 2005, and Oracle 9i. I am having some problems while saving an entity.

My adapter.Save() refetches the entity normally but the issue is with the primary key on the table. The output for the insert statement shows that the primary key is also being inserted with a value '0'. There is an insert trigger on this table that checks if the primary key is null or not and generates the next sequence. Since its not in my case, the insert statement creates a record with PK id = 0 (which is very weird) and the subsequent insert fails as there is already a record with id = 0. If I add a clause in the trigger saying if id is null or if id is zero then generate next sequence, everything works fine. But my DBA is reluctant to add the clause and I am looking for ways to achieve this.

I am not setting the id in my code along with the other properties. How can I avoid passing my primary key into the insert statement...and if it does...how can I set it to null by default. Is there something in the designer or some place else, that takes care of this?

Thanks in advance, --S

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 27-Oct-2006 01:09:58   

As long as you don't specify a value for the field then should not be defined in the query. Can you post the code that you are executing that is causing this behavior?

Emerald
User
Posts: 5
Joined: 01-Aug-2006
# Posted on: 27-Oct-2006 18:10:58   

I found the bug. Its something that we are doing. The object being saved is passed as a DTO. While creating the DTO if the field is set as 'not nullable' then the default value for the type is filled in which is zero in my case. The DTO is then copied into an entity and then the adapter.Save method is called.

So...we need to modify our DTO generation templates to somehow make the primary keys nullable... confused

Thanks for your help.