简体   繁体   English

本机查询以使用SQL触发表锁定(Postgres)

[英]a native query to trigger a table lock using SQL (Postgres)

I would like to make sure that the whole table is locked during my JPA transaction. 我想确保在我的JPA事务期间整个表都被锁定。 As far as i could figure out, there is no JPA Locking Mode to lock the whole table. 据我所知,没有JPA锁定模式可以锁定整个表。 My question is, how does a proper Locking Statement look like and how can i combine it with entity managers merge or persist operations? 我的问题是,适当的Locking Statement外观如何,如何与实体管理器合并或合并操作?

Actually thanks to the comment the solution was following statement: 实际上,感谢评论,解决方案如下:

getEntityManager().createNativeQuery("LOCK TABLE schemaname.tablename").executeUpdate();

The lock will get removed then the transaction (also the one from hibarnate - actually its the same) is over. 锁将被删除,然后事务(也来自hibarnate的事务-实际上相同)结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM