如何将一个实体映射到不同的表

来源:爱站网时间:2021-09-16编辑:网友分享
有我的类TableOne.java:@Table(name =“ table_one”)@EntityListeners(AuditingEntityListener.class)公共类TableOne {@Id @GeneratedValue(generator =“ UUID”)@ ...

问题描述


有我的课TableOne.java

@Table(name = "table_one")
@EntityListeners(AuditingEntityListener.class)
public class TableOne {
    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(
            name = "UUID",
            strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "id", unique = true, nullable = false, updatable = false)
    private String id;

    @CreatedDate
    @Column(name = "created", nullable = false, updatable = false)
    private LocalDateTime created;

    @LastModifiedDate
    @Column(name = "modified", nullable = false)
    private LocalDateTime modified;

    @Column(name = "status_desc")
    private String statusDesc;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(table = "callers")
    private Party caller;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(table = "callee")
    private Party callee;

    ...getter/setter
}

还有Part.java

@Entity
public class Party {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false, updatable = false)
    private long id;

    @Column(name = "desc")
    private String desc;

    @Column(name = "ip")
    private String ip;

    @Column(name = "port")
    private int port;
}

以下字段:调用者,TableOne.java中的被调用者包含相同的字段(id,desc,port,ip),因此我想将它们保留在两个不同的表中。例如:在被调用方和调用方表中。我该怎么做?

思路:


您可以使用两个实体。只需从@Entity中删除Party注释,然后用MappedSuperclass对其进行注释。然后,您可以创建两个实体:

上一篇:将大型xml文件加载到Snowflake中并通过标签进行展平

下一篇:Java错误ENOENT(没有这样的文件或目录)

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载