Entity is not inserted

Posts   
 
    
Kazak
User
Posts: 18
Joined: 25-Aug-2004
# Posted on: 18-Feb-2006 03:54:31   

Scenario:

CREATE TABLE BATCH
(
   BATCH_ID     NUMBER(10)   PRIMARY KEY, 
         -- there is a corresponding sequence object to generate BATCH_ID values
   BATCH_DATE   DATE DEFAULT SYSDATE NOT NULL
);

The following code does not get a batch record inserted to the table unless I uncomment the second line.

BatchEntity batch = new BatchEntity();

// batch.BatchDate = DateTime.Now;

batch.Save();

Environment:

Oracle (ODP.NET 9.2) LLBLGen 1.0.2005.1 February 9, 2006 SelfServicing, two class scenario for VS.NET 2003

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39618
Joined: 17-Aug-2003
# Posted on: 18-Feb-2006 09:33:03   

THis is correct. There aren't any dirty (changed) fields so the entity isn't dirty, so it doesn't insert a row, as there's nothing to save.

Frans Bouma | Lead developer LLBLGen Pro
Kazak
User
Posts: 18
Joined: 25-Aug-2004
# Posted on: 19-Feb-2006 07:36:03   

Then another scenario:

BatchEntity batch = new BatchEntity();
TransactionEntity transaction = new TransactionEntity();
transaction.Amount = 100;
batch.TransactionCollection.Add(transaction);
batch.Save(true);

It fails as the batch record is not inserted at all.

Shouldn't new entities be inserted even if they are not dirty?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39618
Joined: 17-Aug-2003
# Posted on: 19-Feb-2006 12:41:00   

Same issue, Batch isn't dirty, so it's not saved. Transaction has an m:1 relation with Batch, so Batch doesn't get dirty because a transaction is added.

Frans Bouma | Lead developer LLBLGen Pro
Kazak
User
Posts: 18
Joined: 25-Aug-2004
# Posted on: 19-Feb-2006 23:38:34   

Shouldn't NEW entities be inserted even if they are not dirty?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39618
Joined: 17-Aug-2003
# Posted on: 20-Feb-2006 00:23:40   

Kazak wrote:

Shouldn't NEW entities be inserted even if they are not dirty?

No, as that can lead to phantom inserts (i.e. you create an entity but no fields got set, you still get an insert)

Frans Bouma | Lead developer LLBLGen Pro