I have two tables that have a relation ManyToMany and I need to do a query to do some calculations. I have the extra handicap that I have an abstract class Price that I extend from to create the concrete prices (physical presents, money presents, etc)
My problem is that the table COUPON_PRICE doesn't have an Entity so I don't really know how to do a @NamedQuery using that table.
Otherwise everything else is working fine, tables and relations created successfully.
Thank you for any assistance you can provide. :)
Here are the Entity declarations:
Coupon Entity
@Entity
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@Table(name = "ACE_COUPON")
@NamedQueries({
@NamedQuery(name = "Coupon.getAvailableBudget",
query = "SELECT sum(r.amount) "
+ "FROM PhysicalPresent "
+ "JOIN COUPON_PRICE crp on (r.id = crp.ID_PRICE) "
+ "JOIN Coupon cr on (cr.id = crp.ID_COUPON) "
+ "WHERE cr.id = :myID;"),)
public class Coupon {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ID_COUPON")
private Integer id;
@Column(name = "CAMPAIGN_NAME", nullable = false)
private String campaignName;
@Column(name = "COUPON_CODE", unique = true, nullable = false)
private String couponCode;
@Column(name = "STATUS", nullable = false)
private Boolean status;
@Column(name = "CAMPAIGN_BUDGET")
private Double campaignBudget;
@ManyToMany
@JoinTable(name = "COUPON_PRICE", joinColumns =
@JoinColumn(name = "ID_COUPON", referencedColumnName = "ID_COUPON"), inverseJoinColumns =
@JoinColumn(name = "ID_PRICE", referencedColumnName = "ID_PRICE"))
private Set<Price> priceThatBelongsTo;
--constructors, getters and setters--
}
Price Entity
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Price implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ID_PRICE")
private Integer id;
@Column(name = "ID_PRODUCT")
private Integer idProduct;
--constructors, getters and setters--
}
PhysicalEntity
@Entity
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@Table(name = "ACE_PHYSICAL_PRESENT")
public class PhysicalPresent extends Price {
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "AMOUNT")
private Double amount;
@ManyToMany
@JoinTable(name = "COUPON_PRICE", joinColumns = {
@JoinColumn(name = "ID_PRICE", referencedColumnName = "ID_PRICE") }, inverseJoinColumns = {
@JoinColumn(name = "ID_COUPON", referencedColumnName = "ID_COUPON") })
private Set<Coupon> couponsThatBelongsToThisPrice;
--constructors, getters and setters--
}
