How to map two fields to one field in another database column in Spring Data JPA?

Viewed 978

I want to map field firstUser and secondUser in class Channel to field Id in class User but I don't know how to do that. Please help me! Here is my code.....

@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 Answers
Related