Spring JPA:动态提供模式名称 [英] Spring JPA: Providing Schema Name Dynamically
问题描述
我正在构建一个 CRUD 应用程序,我在其中使用 spring 数据 jpa 来处理数据库.我不想在我的实体类中提供架构名称,如下所述.
I am building a CRUD application where I am using spring data jpa to work with Database. I don't want to give schema name in my entity class, like mentioned below.
@Entity
@Table(name = "PROPERTY",schema = "ABC")
public class PropertyDTO extends BaseDTO{
//all the properties and getter,setters
}
当我使用 Repository 获取任何结果时,如果我没有在 My Entity 类中提供架构名称,它会抛出一个错误,说无效的对象名称 PROPERTY,是否还有其他方法可以提及架构名称和框架会在触发查询时附加架构名称吗?
When I will fetch any results using Repository, if I don't provide the schema name in My Entity class, it will throw an error, saying invalid object name PROPERTY, is there any other way where I can mention schema name and Framework will append the schema name while firing query?
推荐答案
如果您需要在运行时更改架构名称,我建议使用 Hibernate 多租户方法.您可以在此处和这里
If you need to change the schema name at the runtime, I recommend to use Hibernate multi-tenancy approach. You could find more details here and here
这篇关于Spring JPA:动态提供模式名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!