在 jpa 中将持久性上下文设置为只读
我们将使用一个旧数据库。 因此,非常重要的是,我们在任何情况下都不要修改数据库/表/模式(来自报告模块),因此我想将一些持久性单元设置为只读的持久性上下文(对于报告模块) ,还有一些像正常的 JTA 一样启用。
我们已经考虑过创建两个帐户在这些持久性单元中使用,一个将被授予只读访问权限,另一个将具有读写访问权限。
我想知道我们是否可以使用 persistence.xml 文件做一些更简单的事情,或者可以在 JDBC 驱动程序级别做一些简单的事情,以便我与数据库的连接根据持久性单元活动有选择地只读和读写。或者正在使用的数据库驱动程序 URL...我们正在使用 SQL-Server 作为数据库服务器...如果这有帮助的话。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,标准 JPA 中不支持这一点(除了使用具有受限数据库连接权限的用户之外)。但是您的 JPA 提供程序可能支持:
@ReadOnly
或 Hibernate@Immutable
注释)eclipselink)对于 EclipseLink,.read-only
设置为true
,对于 Hibernate,将org.hibernate.readOnly
设置为true
)。我检查了连接属性 Microsoft JDBC 驱动程序,但没有发现任何可以提供帮助的信息。
PS:有一个待处理的 EclipseLink 增强请求(Bug 282595)提供对只读
EntityManager
的支持。您可能想投票支持它。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:
@ReadOnly
or Hibernate@Immutable
annotations)eclipselink.read-only
set totrue
for EclipseLink ororg.hibernate.readOnly
set totrue
for Hibernate).I checked the connection properties of the Microsoft JDBC driver but didn't spot anything that could help.
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.