我有两个 JPA 实体:User
和Message
. 每个Message
都有一个sender
和一个receiver
type User
。而在另一边各有User
两组 type Message
:inbox
和outbox
.
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
属性为空。这是如何引起的,我该如何解决?