SQL UPDATE with JPA

505 views
Skip to first unread message

computerpunc

unread,
Oct 12, 2011, 12:03:19 PM10/12/11
to play-framework
How can I update a number of entries in a single JPA request
equivalent to an SQL UPDATE statement?
Something like: public static int update(String query, Object[]
params)?

Thanks,
Punc.

Fehmi Can SAĞLAM

unread,
Oct 12, 2011, 12:14:18 PM10/12/11
to play-fr...@googlegroups.com
I don't know if there is a better way but you can do it like below.

MyModel.em().createQuery("update MyModel set field=:field where
....").setParameter("field", field).executeUpdate();

computerpunc

unread,
Oct 12, 2011, 9:30:21 PM10/12/11
to play-framework
It works for me. Thanks.
I just wished there would be an update method as there are methods for
find, count and delete.

Cheers,
Punc.

On Oct 12, 6:14 pm, Fehmi Can SAĞLAM <fehmican.sag...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages