只读数据库连接与Hibernate [英] Read Only Database Connection with Hibernate

查看:171
本文介绍了只读数据库连接与Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Hibernate并连接到具有只读连接的数据库?我将在一个项目,将需要连接到现有的数据库,从中提取数据,并在应用程序中进行一些复杂的数据操作。在所有这一切,我不能改变数据库中的任何东西,因此只读连接的需求。

Is it possible to use Hibernate and connect to a database with a read only connection? I will be working on a project that will require connecting to an existing database, pulling data from it, and doing some complex data manipulation in the application. Throughout all of this I can`t change anything in the database, hence the read only connection requirement.

我的第一想法是使用Hibernate从数据库中拉数据我可以准备好使Java对象表示数据,但是,我似乎可以找到任何信息,如何强制Hibernate使用只读数据库连接...我有一种感觉,这可能是不可能的,但我

My first thought was to pull the data from the database using Hibernate so that I can have ready made Java objects represent the data, however, I can`t seem to find any information on how to force Hibernate to use a read only database connection ... I have a feeling this might actually be impossible, but I want to find out from others before I pursue other ideas.

推荐答案

我没有足够的声望来评论,显然:(

I don't have enough reputation to comment, apparently :(

但是回应你对Hibernate仍然可能写回数据库的情况的评论,你可以手动将对象从持久化上下文中分离出来,之后Hibernate会停止关心关于对象的状态以及是否已被修改。

But responding to your comment about the cases where Hibernate may still write back to the DB, you could manually detach the object from your persistence context, after which Hibernate would cease caring about the state of the object & whether its been modified.

这篇关于只读数据库连接与Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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