Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 选择“更新不工作”_Java_Mysql_Hibernate_Jboss - Fatal编程技术网

Java 选择“更新不工作”

Java 选择“更新不工作”,java,mysql,hibernate,jboss,Java,Mysql,Hibernate,Jboss,我的以下本机查询不工作: Query createNativeQuery = entityManager.createNativeQuery( "select id from cscache where id=? for update "); 环境详情: Mysql 5.6 JBoss5.1 JPA1.0 错误: 2014-12-12 10:20:14581警告[org.hibernate.util.jdbceptionReporter] SQL错误:1064,SQLState:4200

我的以下本机查询不工作:

Query createNativeQuery = entityManager.createNativeQuery(
   "select id from cscache where id=? for update ");
环境详情:

  • Mysql 5.6
  • JBoss5.1
  • JPA1.0
  • 错误:

    2014-12-12 10:20:14581警告[org.hibernate.util.jdbceptionReporter]

    SQL错误:1064,SQLState:42000(http-0.0.0-8543-3:)

    2014-12-12 10:20:14581错误[org.hibernate.util.jdbceptionReporter] 您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解第1行“limit 2”附近要使用的正确语法(http-0.0.0-8543-3:)


    不太熟悉JPA,但您似乎没有告诉它
    的值是多少。查看。

    对于更新,基本上会对行进行锁定,以便使用您需要使用的JPA实现相同的功能。要设置锁,可以使用EntityManager或TypeQuery,并使用LockModeType.悲观_WRITE


    请参阅

    我实际上没有在hibernate中进行for更新,但我相信您可以(而且应该?)在会话或查询对象上进行更新。为什么不让hibernate执行,而不是执行本机查询? 根据关于锁定()的文档,您可以在会话或查询上设置锁定模式

    Cscache  cscache  = (Cscache )session.get( Cscache.class, id, LockOptions.UPGRADE );
    

    指定锁定选项将导致执行SELECT…FOR UPDATE。

    具有
    limit 2
    查询的代码在哪里?这是唯一一个没有limit 2的代码。我猜Hibernate MySQL方言不支持SELECT FOR UPDATE我在下一行createNativeQuery.setParameter(1,19)中有此选项是的,但它不应该是
    ?1
    而不是
    ?它可以从cscache中选择id,其中id=?但如果您提供更新,它就不起作用。我正在使用JPA 1.0,其中LockModeType.悲观写入不可用