PlayFramework 2 + Ebean - raw Sql update request - does not affect db

I have a play Framework 2.0.4 application that wants to change lines in db.

I need to update "several" messages in db to the state "open" (reading messages) I did it like below

String sql = " UPDATE message SET opened = true, opened_date = now() " +" WHERE id_profile_to = :id1 AND id_profile_from = :id2 AND opened IS NOT true"; SqlUpdate update = Ebean.createSqlUpdate(sql); update.setParameter("id1", myProfileId); update.setParameter("id2", conversationProfileId); int modifiedCount = update.execute(); 

I modified postgresql to register all requests.

modifiedCount is the actual number of modified rows, but the request is executed in a transaction. After the query is executed, there is ROLLBACK in db - so UPDATE will not be executed. I tried changing db to H2 - with the same result.

This is a request from postgres audit log

 2012-12-18 00:21:17 CET : S_1: BEGIN 2012-12-18 00:21:17 CET : <unnamed>: UPDATE message SET opened = true, opened_date = now() WHERE id_profile_to = $1 AND id_profile_from = $2 AND opened IS NOT true 2012-12-18 00:21:17 CET : parameters: $1 = '1', $2 = '2' 2012-12-18 00:21:17 CET : S_2: ROLLBACK 

..........

Play Framework documentation and Ebean documents - states that in the case of a request / no transaction / if it is not declared or transient.

So ... I did the trick

  Ebean.beginTransaction(); int modifiedCount = update.execute(); Ebean.commitTransaction(); Ebean.endTransaction(); Logger.info("update mod = " + modifiedCount); 

But it doesn’t matter - the same behavior ...

 Ebean.execute(update); 

Again, the same thing.

The next step I took - I notifies the method using

 @Transactional(type=TxType.NEVER) 

and

 @Transactional(type=TxType.MANDATORY) 

None of them made a difference.

I'm so upset Ebean :( Can anyone help please?

BTW. I have installed

  Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(true); Ebean.getServer(null).getAdminLogging().setDebugLazyLoad(true); Ebean.getServer(null).getAdminLogging().setLogLevel(LogLevel.SQL); 

to see a request in the Play console - other requests are recorded - this update is not

+7
source share
2 answers

just delete the starting space ... Yes .. I also could not believe ... switch from "UPDATE ... to" UPDATE ...

And all this ...

+4
source

I think you need to use raw sql instead of createSqlUpdate statement.

+1
source

All Articles