在Hibernate JPA:OneToMany更新实体时,如何覆盖默认的删除条件?

时间:2017-10-24 11:06:36

标签: hibernate hibernate-mapping

我观察到,在更新OneToMany关系时,首先hibernate从子实体中删除条目,然后更新子实体中的新数据。有没有办法覆盖默认删除查询或是否可能?

@Entity
@Table(name="USER_PROFILE")
public class UserProfile implements Serializable{

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="PROFILE_ID")
    private Long profileId; 

    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "CAND_USER_LANGUAGE", joinColumns = @JoinColumn(name = "PROFILE_ID"), inverseJoinColumns = @JoinColumn(name = "LANGUAGE_ID"))
    private Set<LanguageMaster> language;
}

在模型中设置值:

Set<UserLanguage> languageSet = some set of UserLanguage;
UserProfile userProfile =  userProfileDao.findByLoginId(usrId);
BeanUtils.copyProperties(userProfile, form);
userProfile.setLanguage(languageSet);
userProfileDao.saveOrUpdate(userProfile);


@Entity
@Table(name = "USER_LANGUAGE")
public class UserLanguage {

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long ID;

    @Column(name = "LANGUAGE_ID")
    private Integer languageId;

    @Column(name = "PROFILE_ID")
    private Long profileId;
}

0 个答案:

没有答案