PlayFramework 2 + Ebean-原始SQL更新查询-对db无效 [英] PlayFramework 2 + Ebean - raw Sql Update query - makes no effect on db

查看:135
本文介绍了PlayFramework 2 + Ebean-原始SQL更新查询-对db无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Play框架2.0.4应用程序,想要修改db中的行.

I have a play framework 2.0.4 application that wants to modify rows in db.

我需要将db中的少量"消息更新为已打开"状态(已读取消息) 我是这样的

I need to update 'few' messages in db to status "opened" (read 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();

我已经修改了postgresql以记录所有查询.

I have modified the postgresql to log all the queries.

modifiedCount是已修改的行的实际数量-但是查询正在事务中. 在数据库中完成查询后,将出现ROLLBACK-因此不会进行UPDATE. 我试图将db更改为H2-结果相同.

modifiedCount is the actual number of modified rows - but the query is in transaction. After the query is done in the db there is ROLLBACK - so the UPDATE is not made. I have tried to change db to H2 - with the same result.

这是来自postgres审核日志的查询

This is the query 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文档和Ebean文档-声明没有事务,如果未声明,则为每个查询,如果需要,则为瞬态.

Play Framework documentation and Ebean docs - states that there is no transaction /if not declared or transient if needed per query/.

所以...我已经成功了

So... I have made the trick

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

但这没什么区别-行为相同...

But this makes no difference - the same behavior ...

Ebean.execute(update);

再次-相同..

我要做的下一步-我用

注释了该方法

Next step i did - I annontated the method with

@Transactional(type=TxType.NEVER)

@Transactional(type=TxType.MANDATORY)

他们都没有改变.

我对Ebean感到非常沮丧:( 有人可以帮忙吗?

I am so frustrated with Ebean :( Anybody can help, please ?

顺便说一句. 我设置

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

要在Play控制台中查看查询-已记录其他查询-此更新-否

to see in Play console the query - other queries are logged - this update - not

推荐答案

只需删除初始空格...是的.我也不敢相信它... 从"UPDATE ...更改为" UPDATE ...

just remove the initial space...Yes..I couldn't believe it either... change from " UPDATE... to "UPDATE...

仅此而已...

这篇关于PlayFramework 2 + Ebean-原始SQL更新查询-对db无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆