JPA with JTA: Persist entity and merge cascaded child entities

前端 未结 4 1629
情歌与酒
情歌与酒 2020-12-20 11:21

I have a bidirectional one-to-many relationship with the following entity classes:

0 or 1 client <-> 0 or more product orders

When persis

4条回答
  •  醉酒成梦
    2020-12-20 11:55

    Use @Joincolumn annotation in your ProductOrder entity, please see below.

       @Entity
       public class ProductOrder implements Serializable, ChildEntity {
       private static final long serialVersionUID = 1L;
    
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       private Long id;
    
       @ManyToOne // owning side
       @JoinColumn(name = "PRODUCTORDER_ID", referencedColumnName = "ID")
       //write your database column names into name and referencedColumnName attributes.
       private Client client;
    
       // other fields, getters and setters
       }
    

提交回复
热议问题