ObjectDB ObjectDB

How to check if an entity exists in a Database without loading it?

#1

Hi,

I am trying to speed up some code - where i check if an entity exists in order to make a decision.

In Java - It looks like this (pk - is the primary key of the entity):

MyClass find  = em.find(MyClass.class, pk);

boolean exists = find != null;

Is there a way to check the existence without loading the entity?

Thanks

 

edit
delete
#2

You can use a query:

SELECT e.pk FROM MyClass e WHERE e.pk = :pk

or

SELECT COUNT(e) FROM MyClass e WHERE e.pk = :pk

 

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.