Hi everybody, I have a problem with Polymorphic Associations. First of all my entities:
@Entity
@Table(name = "customer")
@Inheritance(strategy = InheritanceType.JOINED)
@IdClass(CustomerPk.class)
public class Customer {
@OneToMany(targetEntity=Order.class, mappedBy="customer"
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
}
(PK is lastname and firstname)
@Entity
@Table(name = "privatecustomer")
@PrimaryKeyJoinColumns( { @PrimaryKeyJoinColumn(name = "firstname", referencedColumnName="firstname"),
@PrimaryKeyJoinColumn(name = "lastname", referencedColumnName="lastname") })
public class PrivateCustomer extends Customer {
... additional properties
}
@Entity
@Table(name = "businesscustomer")
@PrimaryKeyJoinColumns( { @PrimaryKeyJoinColumn(name = "firstname", referencedColumnName="firstname"),
@PrimaryKeyJoinColumn(name = "lastname", referencedColumnName="lastname") })
public class BusinessCustomer extends Customer{
... additional properties
}
@Entity
@Table(name = "ord")
public class Order {
@ManyToOne(targetEntity = JPACustomer.class)
@JoinColumns({
@JoinColumn(name="customer_firstname"),
@JoinColumn(name="customer_lastname")
})
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}
Now, my problem is that the association on the customer side is not fetched. No matter which fetchType (Eager, Lazy) i use, hibernate generates no query to fetch the associated orders. No exception, no errors, nothing. Customer.getOrders() simply return null. Have I missed something in my mapping?
thanks for any help
martin
|