views:

170

answers:

1

Does running an EJBQL UPDATE statement defeat the performance benefits of container managed persistance when compared to modifing the accessors on a managed entity?

I'm interested in this specifically for a database load / performance perspective.

For example, if I have an entity called MyEntity and I want to update myField1 and myField2 is there a performance difference between the two following methods:

Query query = em.createQuery("UPDATE MyEntity m SET m.myField1 = :value1, m.myField2 = :value2 WHERE m.id = :id")
query.executeUpdate();

versus

MyEntity myEntity = find("123");

myEntity.setMyField1("newvalue");
myEnttiy.setMyField2("newvalue2");
A: 

No, there isn't a performance difference. If you set your showSql property to true, you can see the generated queries. Both the above variants will generate the same queries (unless autoflush is on, I suppose).

You should try to avoid executing updates and deletes using QL, because it does not handle cascades. In your case you are setting simple string values, so no cascades exist, but have it in mind.

Bozho