Entity Inheritance & abstract Field problem
-------------------------------------------
Key: HHH-3792
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3792
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: JDK6, MySQL
Reporter: Miroslav Nachev
I have one common class CustomerDiscountItem with 2 abstract methods:
@Entity
@Table(name = "customer_discount_items")//, catalog = "acacia_test",
schema = "public")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING, length=2,
name="discriminator_id")
@NamedQueries({
@NamedQuery(
name = "CustomerDiscountItem.findByCustomerDiscount",
query = "SELECT t FROM CustomerDiscountItem t where t.customerDiscount =
:customerDiscount")
})
public abstract class CustomerDiscountItem implements Serializable {
@JoinColumn(name = "customer_discount_id", referencedColumnName =
"customer_discount_id", nullable = false)
@ManyToOne(optional = false)
public abstract CustomerDiscount getCustomerDiscount();
public abstract void setCustomerDiscount(CustomerDiscount customerDiscount);
This class is common for another 2 classes:
public class CustomerDiscountItemByCategory extends CustomerDiscountItem implements
Serializable {
public class CustomerDiscountItemByProduct extends CustomerDiscountItem implements
Serializable {
When I use named query "CustomerDiscountItem.findByCustomerDiscount" the result
is not correct because in where clause only the first class is included:
where cdi_by_category.customer_discount_id=?
The correct where clause should be:
where cdi_by_category.customer_discount_id=? or cdi_by_product.customer_discount_id=?
The whole select statement generated by Hibernate is:
select
cdi.customer_discount_item_id,
cdi.discount_percent,
cdi.discriminator_id,
cdi_by_category.category_id,
cdi_by_category.customer_discount_id as category_cd_id,
cdi_by_category.include_heirs,
cdi_by_product.customer_discount_id as product_cd_id,
cdi_by_product.product_id,
case
when cdi_by_category.customer_discount_item_id is not null then 1
when cdi_by_product.customer_discount_item_id is not null then 2
when cdi.customer_discount_item_id is not null then 0
end as clazz_
from customer_discount_items cdi
left outer join customer_discount_items_by_categories cdi_by_category
on cdi.customer_discount_item_id=cdi_by_category.customer_discount_item_id
left outer join customer_discount_items_by_products cdi_by_product
on cdi.customer_discount_item_id=cdi_by_product.customer_discount_item_id
where cdi_by_category.customer_discount_id=?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira