Hibernate, automatically persist dependant objects

佐手、 提交于 2019-11-29 07:10:34

You have to look at cascading operations; this type of operation permits you to manage lifecycle of inner object respect their parent.

@ManyToOne(cascade) if you use Session.persist() operation or org.hibernate.annotations.@Cascade if you use not JPA function Session.saveOrUpdate().

This is just an example, for full doc point here

For your code, if you want to automatically save Manufacturer when saving Project use:

@ManyToOne (fetch = FetchType.EAGER, cascade = {javax.persistence.CascadeType.PERSIST})
@JoinColumn (name = "mfr_id")
public Manufacturer getManufacturer () {
  return this.manufacturer;
}

or

@Cascade(CascadeType.PERSIST)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!