在jpa中将持久性上下文设置为只读 [英] setting persistence context to read-only in jpa

查看:896
本文介绍了在jpa中将持久性上下文设置为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将使用旧数据库. 因此,在任何情况下(从报告模块中)都不修改数据库/表/方案是非常关键的,因此,我想将一些持久性单元设置为只读的持久性上下文(对于报告模块) ,还有一些已启用的普通JTA.

we are going to be working with an old database. so it is very crucial that we do not modify the database/table/schemas under any circumstances (from the reporting modules), and as such i want to setup a persistence-context with some persistence units as read-only (for reporting modules), and some as normal JTA enabled.

我们已经考虑过创建两个在这些持久性单元中使用的帐户,一个将被授予只读访问权限,另一个将具有读写访问权限.

we have already thought about creating two accounts for using in these persistence units, one will be given read only access, the other will have read-write access.

我想知道是否可以使用persistence.xml文件做些简单的事情,或者可以在JDBC驱动程序级别上做些更简单的事情,以便我与数据库的连接选择性地是只读的,并且基于持久性是可读写的-单位活跃.或正在使用的数据库驱动程序URL ...我们正在使用SQL Server作为DB Server ...如果有帮助的话.

I was wondering if there is something simpler that we can do with the persistence.xml file or may be at the JDBC driver level, so that my connections to the DB are selectively read-only and read-write based on the persistence-unit active. or the database driver url being used... we are using SQL-Server as the DB Server...if that helps any bit.

推荐答案

据我所知,标准JPA中不支持该功能(除了使用具有受限数据库连接权限的用户外).但是您的JPA提供程序可能支持:

To my knowledge there is no support for that (beyond using a user with restricted rights for the database connection) in standard JPA. But your JPA provider might support:

  • 只读实体(例如,带有ElipseLink @ReadOnly或Hibernate @Immutable批注)
  • 通过提示进行只读查询(例如,对于EclipseLink,eclipselink.read-only设置为true;对于Hibernate,org.hibernate.readOnly设置为true).
  • Read-only entities (e.g. with ElipseLink @ReadOnly or Hibernate @Immutable annotations)
  • Read-only queries via hints (e.g. with eclipselink.read-only set to true for EclipseLink or org.hibernate.readOnly set to true for Hibernate).

我检查了连接属性 Microsoft JDBC驱动程序,但没有发现任何可以帮助的东西.

I checked the connection properties of the Microsoft JDBC driver but didn't spot anything that could help.

PS:EclipseLink有待处理的增强请求(错误282595 )以提供对只读EntityManager的支持.您可能需要投票.

PS: There is a pending enhancement request for EclipseLink ( Bug 282595 ) to provide support for a read-only EntityManager. You might want to vote for it.

这篇关于在jpa中将持久性上下文设置为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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