Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring启动在具有多对多关系的实体的PUT时失败_Java_Hibernate_Rest_Spring Boot_Spring Data Rest - Fatal编程技术网

Java Spring启动在具有多对多关系的实体的PUT时失败

Java Spring启动在具有多对多关系的实体的PUT时失败,java,hibernate,rest,spring-boot,spring-data-rest,Java,Hibernate,Rest,Spring Boot,Spring Data Rest,最近我将SpringBoot版本从1.4.0.RELEASE升级到1.4.3.RELEASE。令人惊讶的是,这导致我的一个实体无法使用Spring data rest API使用PUT方法持久化,从而导致: org.hibernate.HibernateException:权限实例的标识符从2更改为3 管理局实体: @Entity public class Authority { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) p

最近我将SpringBoot版本从1.4.0.RELEASE升级到1.4.3.RELEASE。令人惊讶的是,这导致我的一个实体无法使用Spring data rest API使用PUT方法持久化,从而导致:

org.hibernate.HibernateException:权限实例的标识符从2更改为3

管理局实体:

@Entity
public class Authority {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Enumerated(EnumType.STRING)
private AccessLevel authority;
private Integer level;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public AccessLevel getAuthority() {
    return authority;
}

public void setAuthority(AccessLevel authority) {
    this.authority = authority;
}

public Integer getLevel() {
    return level;
}

public void setLevel(Integer level) {
    this.level = level;
}

}
成员实体(拥有权限):

若我在执行请求之前删除了authorities属性,它会工作,但我无法管理权限


恢复到SpringBoot 1.4.0.RELEASE会使此问题消失。您有没有遇到过这样的问题,或者知道可能是什么问题?

原始api/members/8是什么样子的?你想改变什么?让1.4.0和1.4.3都能正常工作。对api/members/8的请求返回正确的json。我正在尝试执行POST/PUT请求,这会导致以下异常:org.hibernate.HibernateException:Authority实例的标识符从2更改为3
@Entity
public class Member extends Auditable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
@Email
private String email;
@Column(unique = true)
@NotNull
private String login;
@NotNull
private String password;
private boolean enabled;
@ManyToMany(fetch = FetchType.EAGER)
private Set<Authority> authorities;

public Member() {
    enabled = true;
    authorities = new HashSet<>();
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getLogin() {
    return login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public boolean isEnabled() {
    return enabled;
}

public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}

public Set<Authority> getAuthorities() {
    return authorities;
}

public void setAuthorities(Set<Authority> authorities) {
    this.authorities = authorities;
}

}
@RepositoryRestResource(exported = false)
public interface AuthorityRepository extends CrudRepository<Authority, Long> {

}
@RepositoryRestResource
public interface MemberRepository extends CrudRepository<Member, Long> {

@RestResource(exported = false)
Member findOneByLogin(String login);

}
{
"created": "2016-10-25T12:44:09.988",
"modified": "2016-10-25T12:44:15.028",
"firstName": "***",
"lastName": "***",
"email": "***",
"login": "***",
"password": "***",
"enabled": true,
"authorities": [{
        "id": 3,
        "authority": "ANALYST",
        "level": 3
    }, {
        "id": 5,
        "authority": "CONTRACTOR",
        "level": 5
    }, {
        "id": 4,
        "authority": "EXPERT",
        "level": 4
    }],
"_links": {
    "self": {
        "href": "https://localhost:8443/api/members/8"
    },
    "member": {
        "href": "https://localhost:8443/api/members/8"
    },
    "modifier": {
        "href": "https://localhost:8443/api/members/8/modifier"
    },
    "creator": {
        "href": "https://localhost:8443/api/members/8/creator"
    }
}
}