I have two classes ServiceFee and DeliveryFee.
@Entity
@Table(name = "service_fees")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula(
"CASE WHEN is_delivery_fee = 1 THEN 'DELIVERY_FEE' ELSE 'SERVICE_FEE' end"
)
public class ServiceFee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "is_delivery_fee")
private Boolean isDeliveryFee;
...
}
and
@Entity
@DiscriminatorValue("DELIVERY_FEE")
public class DeliveryFee extends ServiceFee {
public Enums.DeliveryOption getOrderType() {
return Enums.DeliveryOption.DELIVERY;
}
public Boolean getIsDeliveryFee() {
return Boolean.TRUE;
}
}
My serviceFeeDAO has a method to return all ServiceFees (including the deliveryFees), which works as expected. I added method in the serviceFeeDAO which returns all the deliveryFee, please find code of the same below:
public List<DeliveryFee> getDeliveryFees() {
CriteriaBuilder builder = currentSession().getCriteriaBuilder();
CriteriaQuery<DeliveryFee> query = builder.createQuery(DeliveryFee.class);
Root<DeliveryFee> root = query.from(DeliveryFee.class);
return currentSession().createQuery(query)
.list();
}
invoking this method gave me an IllegalArgumentException
that the DeliveryFee
is not an entity.
Then I went ahead and created a DeliveryDAO class and added this method there. ad now the method returns an empty list.
I am looking to learn why I got the IllegalArgumentException
in the first case, and why the method in the DeliveryFeeDAO won't identity the pick up the delivery fee entities.