我需要在JAVA EE中使用spring MVC创建一个REST应用程序!
我有3个班级,这是个问题:
@Entity
@Table(name= "Brick")
public class Brick {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name="user_id", nullable=false)
private User user;
@ManyToOne
@JoinColumn(name="likable_id", nullable=false)
private Likable likable;
@ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinTable(
name= "Brick_Follower",
joinColumns = { @JoinColumn(name = "brick_id") },
inverseJoinColumns = { @JoinColumn(name = "follower_id") }
)
private Set<User> followers= new HashSet<>();
@OneToMany(mappedBy = "brick")
private List<Comment> comments= new LinkedList<>();
}
@Entity
@Table(name= "Comment")
public class Comment {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@ManyToOne
private Brick brick;
@ManyToOne
private User user;
@Column(length=500)
private String content;
@Temporal(value=TemporalType.TIMESTAMP)
private Date createdDate;
@Entity
@Table(name= "User")
@PrimaryKeyJoinColumn(name="id")
public class User extends Likable {
@Column(nullable=false)
private String firstName;
@Column(nullable=false)
private String lastName;
@Column(nullable=false)
private String email;
private String city;
使用此表模式,我很快就会遇到一个“ StackOverflowError”,我不知道Spring Data是否有可能仅加载“级别”的信息而不是全部关系? 谢谢您的宝贵意见!