我有一个Spring Boot 1.3.5-RELEASE
应用程序用于将JPA
我USERS
与关系相关ROLES
联Bi-directional ManyToMany
。
用户
@Table(name = "Users")
@Entity
public class User extends BaseEntity {
@NotEmpty
@Column(unique = true)
private String username;
@NotEmpty
private String password;
@JoinColumn(name = "user_iid")
@OneToMany
private Set<UserRole> userRoles;
//getters and setters
UserRole(中间表)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "user_iid", "role_iid" }))
@Entity
public class UserRole extends BaseEntity {
@RestResource(exported = false)
@ManyToOne
@NotNull
private User user;
@ManyToOne
private Role role;
//getters and setters
角色
@Entity
public class Role extends BaseEntity {
@NotEmpty
@Column(unique = true)
private String name;
@JoinColumn(name = "role_iid")
@OneToMany
private Set<UserRole> userRoles;
//getters and setters
BaseEntity 是一个带有Ids
和Version
生成器的类。
存储库
@Repository
public interface Repository extends JpaRepository<Role, String> {
Role findByIid(@Param("iid") final String iid);
当我 cURL alocalhost:8080/roles/search/findByIid?iid=1
我得到一个StackOverflow
. 如果对象不存在,则应用程序响应良好。
我已经试过了@JsonIgnore
但不起作用。
谢谢