Hibernate, automatically persist dependant objects

后端 未结 1 1759
再見小時候
再見小時候 2020-12-18 04:32

I\'m quite new to Hibernate and have been trying to determine what it will do for you and what it requires you to do.

A big one is dealing with an object that has

相关标签:
1条回答
  • 2020-12-18 04:59

    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)
    
    0 讨论(0)
提交回复
热议问题