There is entity by name Transaction
which has two mapped(@OneToOne
) child entities by name ServiceTransaction
and OtherFeeTransaction
. Able to filter using Specification for all the fields but for the child entity fields at the same time.
Transaction Entity:
public class Transaction implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "uuid")
private UUID id;
@Column(name = "txn_id")
private String txnId;
@Column(name = "account_no")
private String accountNo;
@Column(name = "date", nullable = false)
private Date date;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "service_id")
private ServiceTransaction serviceTransaction;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "other_id")
private OtherFeeTransaction otherFeeTransaction;
}
OtherFee Entity:
public class OtherFeeTransaction implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "uuid")
private UUID id;
@Column(name = "other_fee_id")
private UUID otherFeeId;
@Column(name = "type_data_id")
private String typeDataId;
}
Service Entity:
public class ServiceTransaction implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "uuid")
private UUID id;
@Column(name = "parcel_id")
private String cadastreId;
@Column(name = "ba_unit_id")
private String titleId;
}
Specification
Predicate service = cb.like(root.<ServiceTransaction>get("serviceTransaction").get("titleId"),
"%" + criteria.getTitleId() + "%");
Predicate other = cb.like(root.<OtherFeeTransaction>get("otherFeeTransaction").get("typeDataId"),
"%" + criteria.getTitleId() + "%");
//works if any one of the predicates is added, but doesn't work if both given like below
predicateList.add(service);
predicateList.add(other);
criteriaQuery.where(cb.and(predicateList.toArray(new Predicate[predicateList.size()])))
.getRestriction();
If any one of the predicate
's service
or other
is given able to get the result but not if both predicates
given.
Even tried with or caluse
it deos not work