views:

31

answers:

2

All my entities can not be deleted - only deactivated, so they don't appear in any read methods (SELECT ... WHERE active=TRUE).

Now I have some 1:M tables on this entities on which all CRUD operations can be executed.

What is more efficient or has better performance?

My first solution: To add to all CRUD operations:

UPDATE ... JOIN entity e ... WHERE e.active=TRUE

My second solution: Before all CRUD operations check if entity is active:

if (getEntity(someId) != null) {
    //do some CRUD
}

In getEntity there's just SELECT * FROM entity WHERE id=? AND active=TRUE.

Or any other solution, recommendation,...?

+1  A: 

Second, plus an active second level cache ;) Chance is that the object already is in memory. Chance is acutally pretty high.

TomTom
Good idea - I am already using Hibernate with caching!
Trick
A: 

I would move all deactivated entities to a separate table and not worry about the entity being active.

bleeeah
This would follow to foreign key error then.
Trick