0

我有两个 JPA 实体:UserMessage. 每个Message都有一个sender和一个receivertype User。而在另一边各有User两组 type Message:inboxoutbox.

Message

@Entity
@Table(name = "messages")
public class Message {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq")
    @SequenceGenerator(name = "seq", sequenceName = "MESSAGES_SEQ")
    @Column(name = "ID", insertable = false, updatable = false)
    private int id;
    @ManyToOne
    @JoinColumn(name = "SENDER")
    private User sender;
    @ManyToOne
    @JoinColumn(name = "RECEIVER")
    private User receiver;
    private String subject, content;
    private Date sdate;
    //getters and setters
}

所有未使用注解映射的属性与数据库中的列具有相同的名称,并由 JPA 自动映射。

User

@Entity
@Table(name = "users")
public class User {
    @Column(name = "USERNAME")
    private String username;
    @Column(name = "PASSWORD")
    private String pass;
    @Column(name = "EMAIL")
    private String email;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq")
    @SequenceGenerator(name = "seq", sequenceName = "USERS_SEQ")
    @Column(name = "ID", insertable = false, updatable = false)
    private int id;
    @OneToMany(mappedBy = "uploader")
    private Set<Book> books;
    @OneToMany(mappedBy = "receiver")
    private Set<Message> inbox;
    @OneToMany(mappedBy = "sender")
    private Set<Message> outbox;
    //getters and setters
}

问题是,当我User从 Oracle 数据库中选择一个时,该inbox属性为空。这是如何引起的,我该如何解决?

4

0 回答 0