[英]Spring Data JPA- Having two JPA entities that reference a database table that isnt an entity
Bit of a use case question.一个用例问题。 We want to create a new application with new JPA entity's X and Y, we want to be able to create a reference/relationship inside one of our JPA entity's x to an already existing database table z in the same database.
我们想用新的 JPA 实体的 X 和 Y 创建一个新的应用程序,我们希望能够在我们的 JPA 实体的 x 中创建一个引用/关系到同一数据库中已经存在的数据库表 z。 We dont want this new application to be able to manage the data in table z( another application does that) but just essentially read from it.
我们不希望这个新应用程序能够管理表 z 中的数据(另一个应用程序会这样做),而只是从本质上读取它。 Essentially table X in JPA would have a collection of Z objects in a one to many relationship mapped by Z's primary key
本质上,JPA 中的表 X 将具有由 Z 的主键映射的一对多关系中的 Z 个对象的集合
Anyone got any insights of what we need to do to implement this?任何人都对我们需要做些什么来实现这一点有任何见解?
My advice is to create a new database user with READ-WRITE permission on all the tables, except those where you need READ-ONLY permission.我的建议是创建一个对所有表具有 READ-WRITE 权限的新数据库用户,除了那些需要 READ-ONLY 权限的用户。 You will use this newly created user in datasource connection with the guarantee that your application will not execute unwanted modifications.
您将在数据源连接中使用这个新创建的用户,并保证您的应用程序不会执行不需要的修改。
For formal correctness you should also mark readonly @Immutable
read-only entities为了形式正确,您还应该标记 readonly
@Immutable
只读实体
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.