JPA:OneToMany,获取所有者实体的子集

时间:2016-04-14 09:28:51

标签: java jpa one-to-many

我有这两个实体:

@Entity
@Table(name = "commande")
public class Commande implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "name")
    private String name;

    @OneToMany(mappedBy = "commande")
    @JsonIgnore
    private Set<Piece> pieces = new HashSet<>();



@Entity
@Table(name = "piece")
public class Piece implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "ref")
    private String ref;

    @ManyToOne
    private Commande commande; 

当我加载实体Commande时,如果有与此命令相关联的部分,我希望其属性部分不为空。 我怎样才能做到这一点?

谢谢。

0 个答案:

没有答案