I have following object mapping in our project. One contact can have multiple quotes from typeA and typeB.
Code:
@Entity
@Table(name = "t_ind_contact")
public class Contact implements Serializable {
@Id
@Column(name = "id", unique = true)
private Long id;
@OneToMany
private List<Quote> quotes;
}
Abstract Quote class.
@Entity
@Inheritance
@DiscriminatorColumn(name = "app_code")
@Table(name = "t_ind_quote")
public abstract class Quote implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
private long id;
@OneToMany
@JoinColumn(name = "contact_id")
private Contact contact;
@Column(name = "app_code", insertable = false, updatable = false)
private int appCode;
}
TypeA Quote class
@Entity
@DiscriminatorValue("1")
public class TypeAQuote implements Serializable {
private static final long serialVersionUID = 1L;
}
TypeB Quote class
@Entity
@DiscriminatorValue("2")
public class TypeBQuote implements Serializable {
private static final long serialVersionUID = 1L;
}
This mapping is working fine for all operations. But for some operations we need the contact object with typeA quotes only. As of now, we will filter typeA quotes after system loads data from the database.
Is there a way that we can populate a contact object only with typeA quotes? I mean even the generated queries will load only typeA quotes.