我对多对多关系有疑问。
在这里我将粘贴代码
User.kt
@Entity
@Getter
@Setter
@Builder
@Inheritance(strategy = InheritanceType.JOINED)
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "USER", schema = "public")
data class User(
@JsonView(Views.Base::class)
var username: String,
@JsonView(Views.UserExtended::class)
@OneToMany(mappedBy = "user", cascade = [CascadeType.ALL], orphanRemoval = true)
@JsonManagedReference
var projects: List<UserProject>? = mutableListOf()
UserProject.kt
@Entity
@Getter
@Setter
@Builder
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "USER_PROJECT", schema = "public")
data class UserProject(
@JsonView(Views.ProjectExtended::class)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
val user: User?,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "project_id")
val project: Project?,
@JsonView(Views.ProjectExtended::class)
val projectRole: String
) : BaseEntity() {}
Project.kt
@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "PROJECT", schema = "public")
data class Project (
@JsonView(Views.Base::class)
val name: String?,
@OneToMany(mappedBy = "project", cascade = [CascadeType.ALL], orphanRemoval = true)
@JsonView(Views.ProjectExtended::class)
var users: List<UserProject>?
) : BaseEntity() {}
我正在经历无限循环。 我所做的只是简单地执行Views来解决问题。但是我也在@RepositoryRestResource上使用QueryDSL,这给了我关于URL的自动谓词 问题是,我不能简单地将 @Jsonview 添加到RepositoryRestResource接口。
我尝试过进行投影,但是它给了我无限循环的结果,因为 @JsonView 在投影和界面上不起作用
有人建议我如何解决这个问题?