Paw*_*iak 7 postgresql transactions sql-update ebean playframework-2.0
我有一个想要修改db中的行的play framework 2.0.4应用程序.
我需要将db中的'less'消息更新为"打开"状态(读取消息)我就像下面这样做了
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();
Run Code Online (Sandbox Code Playgroud)
我修改了postgresql来记录所有查询.
modifiedCount是修改行的实际数量 - 但查询是在事务中.在db中完成查询之后会有ROLLBACK - 因此不会进行UPDATE.我试图将db更改为H2 - 结果相同.
这是来自postgres审核日志的查询
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
Run Code Online (Sandbox Code Playgroud)
..........
Play Framework文档和Ebean文档 - 声明没有事务/如果没有声明或者每个查询需要瞬态.
所以...我已经成功了
Ebean.beginTransaction();
int modifiedCount = update.execute();
Ebean.commitTransaction();
Ebean.endTransaction();
Logger.info("update mod = " + modifiedCount);
Run Code Online (Sandbox Code Playgroud)
但这没有区别 - 同样的行为......
Ebean.execute(update);
Run Code Online (Sandbox Code Playgroud)
再次 - 相同..
我做了下一步 - 我用方法取消了方法
@Transactional(type=TxType.NEVER)
Run Code Online (Sandbox Code Playgroud)
和
@Transactional(type=TxType.MANDATORY)
Run Code Online (Sandbox Code Playgroud)
他们都没有什么区别.
我对Ebean感到非常沮丧:(有人可以帮忙吗?
BTW.我设置
Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(true);
Ebean.getServer(null).getAdminLogging().setDebugLazyLoad(true);
Ebean.getServer(null).getAdminLogging().setLogLevel(LogLevel.SQL);
Run Code Online (Sandbox Code Playgroud)
在Play控制台中查看查询 - 记录其他查询 - 此更新 - 不是