小编mdo*_*oud的帖子

是否可以在实体中映射字段而不定义任何关联?

我在DB中有以下架构(简化)

MainTable(
    ID primary key
    SOMEFIELD
    CODE_FK1 -- references OtherTable1 CODE (without declared foreign key)
    CODE_FK2 -- references OtherTable2 CODE (without declared foreign key)
    ... Other fields used
)

OtherTable1(
    CODE primary key
    LABEL
    ... other fields not used
)

OtherTable2(
    CODE primary key
    LABEL
    ... other fields not used
)
Run Code Online (Sandbox Code Playgroud)

我问是否有任何方法可以为主表定义我的实体,以便直接使用其他表中的标签,即不为这些其他表定义实体.

我无法更改数据库架构,这非常糟糕(在多个表中定义了标签/代码耦合,在多个表中定义).如果有可能,这个解决方案将允许我的代码简单,因为我真的不需要这些其他实体.

我猜它会产生类似的结果:

@Entity
public class MainEntity{
    @Id
    private Integer ID;

    @Column(name="SOMEFIELD")
    private String SomeField;

    @SomeAnnotation to Join CODE_FK_1 with OtherTable1.CODE
    @SomeAnnotation like @Column(name="LABEL", table="OtherTable1")
    private String Label1;

    @SomeAnnotation …
Run Code Online (Sandbox Code Playgroud)

java mapping hibernate

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×1

java ×1

mapping ×1