I'm having some problems getting results for our payment code. Do I need a mapping from the subclass to the super? All I get from the query(listed below) is null for any of the values for Payment33DigitCode, yet can get values for PaymentSource such as the ID.
Super: @Entity @GenericGenerator(name="sequence", strategy="sequence",parameters=@Parameter(name="sequence", value="S_PAYMENT_SOURCE_ID")) @Inheritance(strategy=InheritanceType.JOINED) @Table(name="PAYMENT_SOURCES") public abstract class PaymentSource implements PaymentSourceVisitable{ protected PaymentSource() { // Hibernate constructor } public void accept(PaymentSourceVisitor visitor){ visitor.visit(this); } private Integer paymentSourceId;
@Id @GeneratedValue(generator="sequence") @Column(name="PAYMENT_SOURCE_ID") public Integer getPaymentSourceId() { return paymentSourceId; }
public void setPaymentSourceId(Integer paymentSourceId) { this.paymentSourceId = paymentSourceId; } }
Subclass: @Entity @Table(name="PAYMENT_33_DIGIT_CODE") public class Payment33DigitCode extends PaymentSource implements PaymentSourceVisitable{
private String tub; private String org; private String object; private String fund; private String activity; private String subactivity; private String root; Payment33DigitCode() { super(); // Hibernate constructor } public Payment33DigitCode(String tub, String org, String object, String fund, String activity, String subactivity, String root) { super(); this.tub = tub; this.org = org; this.object = object; this.fund = fund; this.activity = activity; this.subactivity = subactivity; this.root = root; } public void accept(PaymentSourceVisitor visitor){ visitor.visit(this); } @Column(name="TUB") public String getTub() { return tub; } public void setTub(String tub) { this.tub = tub; } @Column(name="ORG") public String getOrg() { return org; } public void setOrg(String org) { this.org = org; } @Column(name="OBJECT") public String getObject() { return object; } public void setObject(String object) { this.object = object; } @Column(name="FUND") public String getFund() { return fund; } public void setFund(String fund) { this.fund = fund; } @Column(name="ACTIVITY") public String getActivity() { return activity; } public void setActivity(String activity) { this.activity = activity; } @Column(name="SUBACTIVITY") public String getSubactivity() { return subactivity; } public void setSubactivity(String subactivity) { this.subactivity = subactivity; } @Column(name="ROOT") public String getRoot() { return root; } public void setRoot(String root) { this.root = root; } }
Queries I've used: Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Requisition.class, "requisition"); criteria.createAlias("requisition.orders","requisitionOrder"); criteria.createAlias("requisitionOrder.payments","requistionOrderPayment"); criteria.createAlias("requistionOrderPayment.paymentSource","Payment33DigitCode"); criteria.add(Restrictions.eq("requisition.requisitionNumber", reqNumber)); criteria.setProjection(Projections.projectionList() .add(Projections.property("requisitionOrder.orderNumber")) .add(Projections.property("Payment33DigitCode.tub")) .add(Projections.property("Payment33DigitCode.org")) .add(Projections.property("Payment33DigitCode.object")) .add(Projections.property("Payment33DigitCode.fund")) .add(Projections.property("Payment33DigitCode.activity")) .add(Projections.property("Payment33DigitCode.subactivity")) .add(Projections.property("Payment33DigitCode.root")) ); List<Payment33DigitCode> payment33DigitCodes = (List<Payment33DigitCode>)criteria.list(); /* Tried to use HQL as well. .createQuery("select rot.order_number, pd.tub, pd.org, pd.object, pd.fund, pd.activity," + "pd.subactivity, pd.root " + "from RequisitionOrder ro " + "join ro.payments rop " + "join rop.paymentSource " + "where ro.requitsition = :reqNumber" + "and paymentSource ") .setParameter("reqNumber", reqNumber); */ return(payment33DigitCodes); }
|