问题描述
我想知道是否有办法从会话工厂获取默认模式名称,不知何故?我需要得到它的原因是因为我必须使用一个本地SQL,并且我有多个会话工厂用于多个模式和一个数据源。所有生成的hibernate查询都由可以选择访问其他模式的单个用户运行。
I was wondering if there is a way to get the default schema name from session factory, somehow? The reason I need to get it is because I have to use a one native SQL and I have multiple session factories for multiple schemas and a single data source. All the generated hibernate queries are being ran by a single user which has select access to other schemas.
推荐答案
我刚发现hibernate有{h-schema}替换,可用于原生sql查询。因此,当您连接到Oracle数据库中的一个模式并希望针对不同模式执行查询时,它可以干净地完成这项工作。例如:
I just found out that hibernate has {h-schema} replacement that can be used in native sql queries. So this does the job cleanly when you are connected to a one schema in oracle database and want to execute queries against different schemas. Example would be:
select * from {h-schema}table_name
通过这种方式,不用在查询中执行手动 replaceAll
,hibernate会照顾所有的事情,会话工厂使用hibernate.default_schema
属性进行配置。
This ways instead of doing a manual replaceAll
in a query, hibernate will take care of everything given that each session factory is configured with "hibernate.default_schema"
property.
这篇关于从会话工厂以编程方式获取休眠默认模式名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!