如何将两个字段映射到Spring Data JPA中另一个数据库列中的一个字段?

时间:2017-09-15 07:56:07

标签: java spring jpa spring-data-jpa

我想将类Channel中的字段firstUser和secondUser映射到类User中的字段Id,但我不知道该怎么做。请帮我!这是我的代码.....

@Entity
@Table(name = "tb_user")
public class User implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "firstname")
    @NotNull(message = "Firstname can not be null")
    private String firstName;

    @Column(name = "lastname")
    @NotNull(message = "Lastname can not be null")
    private String lastName;

 .....
 }

@Entity
@Table(name = "tb_message_channel")
public class Channel {

    private int firstUser;
    private int secondUser;

    @Column(name = "channel_uuid")
    private String channelId;

    @Column(name = "created_date")
    @CreationTimestamp
    private Timestamp createdDate;

......
}

0 个答案:

没有答案