@Entity
public class Coupon implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "coupon", cascade={CascadeType.PERSIST, CascadeType.MERGE})
private List<Encasement> facEncaissements = new ArrayList<Encasement>(0);
@Formula("(SELECT DISTINCT TOP 1 e.ChequeNumber FROM Encasement e WHERE e.IdCoupon = Id)")
private String chequeNumber;
}
@Entity
public class Encasement implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "IdCoupon")
private Coupon coupon;
private String chequeNumber;
}