When creating entity and related entities the FK values remain empty

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 23-Apr-2010 15:59:52   

Hi,

I'm creating an entity and some related entities also. A trigger is setting the PK values for all entities while inserting. The related entities are inserted correctly, except the fact, the FKs are empty.

My code:


            var tabulka = new XfTabulkyEntity();
            
            //not a PK
            tabulka.Entitynazov = "nazov";
            
            for (int i = 0; i < coll.Count; i++)
            {
                var field =coll[i];

                var stlpec = new XpTabulkyStlpceEntity();

                stlpec.FlSortable = false;
                stlpec.Stlpec = field.Name;
                stlpec.Nazovpregrid = field.Name;

                tabulka.XpTabulkyStlpce.Add(stlpec);
            }

            using(var adapter = new DataAccessAdapter())
            {
                    adapter.SaveEntity(tabulka);
            }

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 23-Apr-2010 16:38:10   

I've found something interesting. When I save my entity,which gets its PK assigned by a trigger when inserting, and refetchAfterSave is true, the entity will not be refetched properly.

I've took a look on the generated SQL and I realized why is this happening.

The generated SQL:


Query: INSERT INTO "SMTAPP"."XF_TABULKY" ("TABULKA", "ENTITYNAZOV") VALUES (:Tabulka1, :Entitynazov2)
    Parameter: :Tabulka1 : String. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: "xx".
    Parameter: :Entitynazov2 : String. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: "xx".



SELECT "SMTAPP"."XF_TABULKY"."ID" AS "Id", "SMTAPP"."XF_TABULKY"."TABULKA" AS "Tabulka", "SMTAPP"."XF_TABULKY"."ORDERBY" AS "Orderby", "SMTAPP"."XF_TABULKY"."ENTITYNAZOV" AS "Entitynazov" FROM "SMTAPP"."XF_TABULKY" WHERE ( ( "SMTAPP"."XF_TABULKY"."ID" IS NULL))


Is there any solution for this situation ? We have this triggers setting PK thing all across our DB.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Apr-2010 02:54:42   
David Elizondo | LLBLGen Support Team
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 27-Apr-2010 10:41:32   

I'm using Oracle. When using the identity true option, you have to choose a sequencer.

But in our enviroment we have triggers on our tables, which are checking the primary keys values on insert event for null and if the value is null then a vaule from the sequencer is inserted.

This works fine,but I'm can't refetch an entity after it's been saved. Is this even possible in our trigger scenario ?

Runtime version 2.6.9.1202

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 27-Apr-2010 11:11:55   

First thing to do is to set the Sequence for the field in the Designer.

Then check Trigger based sequence values