开发者

Does an EJB-QL UPDATE statement defeat CMP

Does running an EJBQL UPDATE开发者_StackOverflow社区 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");


Performance differs in both cases.

When we use

em.createQuery("UPDATE MyEntity myEntity SET myEntity.myField1="+myField1).executeUpdate();

performance is better then another case.

Because in other case when first we take data, set its value and then save --|-Ñ-|-- but that not in other case.

By Narendra Choyal


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜