简体   繁体   English

从不同的数据库生成实体,并创建链接两个实体的组合

[英]generate entities from different databases and create composite linking two entities

I am pretty new to EclipseLink. 我对EclipseLink很陌生。

Iwould like to know : 我想知道 :

  1. is it possible to create entities from 2 differents databases ? 是否可以从2个不同的数据库创建实体? if yes, how ? 如果是,如何? (example please) (请举个例子)

  2. let's say I have Database1 and Database2, is it possible to create composite unit whose one field of entity 1 from database 1 is an entity 2 from database 2. if yes, how (example please) 假设我有Database1和Database2,是否可以创建一个复合单元,其数据库1的实体1的一个字段是数据库2的实体2。如果是,请(例如)

Thank you very much 非常感谢你

Assuming two different schemas on the same server, you should be able to do this using the @SecondaryTable annotation which allows you to map one entity to 2 or more tables. 假设同一台服务器上有两个不同的架构,则应该能够使用@SecondaryTable批注执行此操作,该批注允许您将一个实体映射到2个或多个表。 The annotation allows you to specify to the schema or catalog containing the secondary table. 批注允许您指定包含辅助表的架构或目录。

https://docs.oracle.com/javaee/5/api/index.html?javax/persistence/SecondaryTable.html https://docs.oracle.com/javaee/5/api/index.html?javax/persistence/SecondaryTable.html

Would look something like: 看起来像:

@Entity
@Table(name = "main_table")
@SecondaryTable(name="secondary_table", schema="secondary_schema")
public class MyEntity{

    @Column(name = "my_field", table="secondary_table")
    private String fieldFromSecondaryTable;
}

If you are talking about two different servers then you can look at doing something at the database level which would allow you to create a DB view and then map an entity to this view. 如果您正在谈论两个不同的服务器,那么您可以考虑在数据库级别执行一些操作,这将允许您创建数据库视图,然后将实体映射到该视图。 This would work for read operations but not sure about writing... 这将适用于读取操作,但不确定写入...

In SQL Server, for example, you would be looking at creating a Linked Server: 例如,在SQL Server中,您将要创建一个链接服务器:

Selecting data from two different servers in SQL Server 从SQL Server中的两个不同服务器中选择数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM