JPA How can I get the generated id/object when using merge from parent but child is created?

前端 未结 4 1581
孤独总比滥情好
孤独总比滥情好 2021-01-04 20:47

I have an entity that has been previously persited and has a @OneToMany relationship with another entity. In order to add a new entity I just add my new entity

4条回答
  •  盖世英雄少女心
    2021-01-04 21:12

    You should be able to "see" a generated ID for a new Entity:

    • after transaction commits, or

    • after a em.flush() (where em is your EntityManager) while a transaction is active.

    Note also that all relationships between Entities need to be resolved in the Java data structures prior persistence. Child references to parents need to be "set", and vice-versa.

提交回复
热议问题