我有两个实体User和Wish:

@Entity
@Table(name = "T_USER")
public class User implements Serializable {

    @Column(length = 50)
    private String lastname;

    @Column(length = 50)
    private String firstname;

    @OneToMany(mappedBy = "user",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Wish> wishes = new HashSet<Wish>();

    // getters and setters

}

@Entity
@Table(name = "T_WISH")
public class Wish implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "title")
    private String title;


    @Column(name = "description")
    private String description;

    @ManyToOne
    private User user;

    // getters and setters

    }


当我保存用户时,原因原因原因募集者ID为null。我试过了 :

Wish wish = wishRepository.save(wish);
        user.getWishes.add(wish);
    User userSaved =    userRepository.save(user);


为什么未设置招聘者ID。

最佳答案

您的用户类没有@Id附加字段。

10-08 14:02