简体   繁体   中英

Why Hibernate ManyToOne is not persisted correctly?

I have two entities User and 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

    }

When i save the user, recruiter_id is null why. I've tried :

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

Why the recruiter_id is not set.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM