When calling CRUD check if "parent" exists with read or join?

Posted by Trick on Stack Overflow See other posts from Stack Overflow or by Trick
Published on 2010-03-09T09:14:15Z Indexed on 2010/03/09 9:21 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

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,...?

© Stack Overflow or respective owner

Related posts about java

Related posts about sql