Partial updates & inserts

Posts   
 
    
RaFaLe avatar
RaFaLe
User
Posts: 27
Joined: 26-Oct-2006
# Posted on: 27-Mar-2007 11:33:35   

Hi all,

We are using the Adapter Scenario.

We have the following object hierarchy :

ArticleEntity -> CustomerArticleEntity -> StaffCustomerArticleEntity

(StaffCustomerArticleEntity extends CustomerArticleEntity which extends ArticleEntity).

All staff customers have an entry in StaffCustomerArticleEntity which stores their staff number.

The problem is: If we try to change a normal customer to a staff customer, an entry in StaffCustomerArticle is required, however, CustomerArticle entry already exists. If we attempt to insert into StaffCustomerArticle, a duplicate key exception is raised when the insert is attempted on CustomerArticle (as it should be).

Is there any way to ONLY insert into the StaffCustomerArticle, using the existing keys from CustomerArticle?

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 27-Mar-2007 17:03:55   

Hi,

I think you must remove the hierarchy between these entities if you want change the type of an entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 28-Mar-2007 10:57:10   

The thing is: doing so will change the type of an EXISTING instance. the data in the db is an existing instance of an entity. This is similar to being able to change the type of an OBJECT in memory. You also can't do that for the same reasons as why you shouldn't do it in the db.

The solution then is to remove the customer and re-add it as staffcustomer.

However, typically, this precise problem is often a signal that the hierarchy isn't necessary: if you have an instance I of type A and it can morph into type B, you should consider a 'role' attribute (field) in I instead, which signals if I is an A or a B.

Frans Bouma | Lead developer LLBLGen Pro