EclipseLink - bidirectional OneToMany relation

后端 未结 2 1888
悲&欢浪女
悲&欢浪女 2021-01-15 05:39

Let\'s say I have two entities:

@Entity
public class Customer implements Serializable {
    ...
    @OneToMany(cascade=ALL, mappedBy=\"customer\")
    public         


        
2条回答
  •  醉话见心
    2021-01-15 06:06

    Jpa does not maintain relationships for you, the application is required to set both sides of bidirectional relationships to keep them in synch with the database. Add order to the orders list when you set the order->customer relation and if customer is detached, merge it to have the changes to the collection picked up.

    Otherwise you will need to explicitely refresh using em.refresh or a query with a refresh query hint after the transaction, or evict the customer from the caches. Either way, it requires a database hit that is easily avoided by just maintaining both sides of relationships.

提交回复
热议问题