ORA-02291 during saveChanges

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
PJourdat
Posts: 1
Joined: Wed 15 Jul 2009 08:05

ORA-02291 during saveChanges

Post by PJourdat » Wed 15 Jul 2009 08:28

The database Model is this One

table PARAMETER_DEFINITION
paramaterId
parameterName

table PRODUCT
productId
productVersion


table PRODUCT_PARAMETER
parameterId
productId
productVersion


The Primary keys are bold
The table PRODUCT_PARAMETER has a foreign key with PARAMETER_DEFINITION and a foreign key with PRODUCT.

With Entity Framework (and DEVART) we try to create a new product with its new parameter (the parameterDefintion already exists).
Here is the code :
ProductionHandlerEntities EdmProduction = new ProductionHandlerEntities();
Product myProduct = Product.CreateProduct("MyProductId", "MyProductVersion");
EdmProduction.AddToProductSet(myProduct);
myProduct.Name = "MyProduct";
//Create a parameter which depends to MyProduct and to the parameterDefinition "ERP_CSV"
ProductParameter theProductParameter = ProductParameter.CreateProductParameter("ERP_CSV", myProduct.ProductId, myProduct.ProductVersion);
EdmProduction.AddToProductParameterSet(theProductParameter);
theProductParameter.ParameterDefinitionReference.EntityKey = ParameterDefinition.CreateParameterDefinitionKey("ERP_CSV");
myProduct.Parameters.Add(theProductParameter);
EdmProduction.SaveChanges();

This code fails with :
System.Data.UpdateException: An error occurred while updating the entries. See the InnerException for details. ---> Devart.Data.Oracle.OracleException: ORA-02291: integrity constraint (PRODUCIM.FK1_AFFECT_PRM_PROD) violated - parent key not found

The FK1_AFFECT_PRM_PROD is the foreign key between ProductParameter and product.
It seems that "devart entity framework" try to insert into PRODUCT_PARAMETER before into PRODUCT.

Thanks for your help

Pierre Jourdat

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 15 Jul 2009 14:04

Please send us (support * devart * com) the script of db objects you use.

hennieg
Posts: 2
Joined: Wed 09 Sep 2009 13:20
Location: the netherlands

Any progress on the ORA-02291 error with SaveChanges?

Post by hennieg » Wed 09 Sep 2009 13:25

I have encountered exactly the same problem described in the post by PJourdat. When creating a new master record and a new related detail record using EntityFramework, I get the ORA-02291 error when calling SaveChanges.

When I retrieve a previously saved master record and create a new related detail record, everything goes as expected.

Any new suggestions on this? I am willing to specify additional information if necessary. Please let me know.

Thanks!
Hennie Gottenbos.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 11 Sep 2009 13:07

Hennieg, have you tried the latest 5.25.42 build of dotConnect for Oracle? If the problem persists with the 5.25.42 build too, please send us (http://www.devart.com/company/contact.html) a small test project with the script of db objects. We cannot reproduce the issue.

hennieg
Posts: 2
Joined: Wed 09 Sep 2009 13:20
Location: the netherlands

Problem solved using StoreGeneratedPattern="Identity"

Post by hennieg » Mon 14 Sep 2009 08:45

Strange that you could not reproduce this problem. I found mention of similar problems in the Devart forums related to IDs generated by the database using a trigger and a sequence. Manually adding StoreGeneratedPattern="Identity" tag to the Property elements for the ID fields of both the master and the detail records in the .edmx file solved the problem.

This does however mean this manual addition needs to be done whenever the model is regenerated after working in the EF Designer. Not really a viable solution for large projects. Hopefully a more structured solution will become available in due course.

To be clear: I did try 5.25.42 build but this did not solve the problem. The use of the StoreGeneratedPattern tag was still necessary.

Best,
Hennie.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 16 Sep 2009 14:09

The situation is rather difficult.
First, Oracle does not have any mechanism to indicate that the column is an autoincrement one, unlike other databases
(SQL Server's Identity column, for example, or MySQL auto_increment).
But Entity Framework should be aware of it, that's why there is a need to set StoreGeneratedPattern to "Identity".
Microsoft Update model from database wizard overwrites all manual changes.
Unfortunately we cannot change this behaviour.
As an alternative, try to use Devart Entity Developer. It gives limited opportunities to update,
but you are able to add new entities to the model, and the manual changes are preserved.

Post Reply