When I execute a Criteria in Hib3.1, everything works ok. However, when I run the same exact query in the hibernate version bundled with 404GA-JEMS, I get a table generated twice.
The table in question is part of a recursive relationship:
Fulfillment => Invoice => Sale
All of these classes are a sub-class of AbstractOrder which has a "parent" property that points back to an AbstractOrder. When I execute a criteria query that starts with the Fulfillment and reference the parent.parent mapping, invalid SQL is generated.
I am using the following criteria query for both Hib3.1 and 404GA-JEMS:
Code:
Session s = DBUtilsForTest.getAnnotationSession();
Criteria criteria = s.createCriteria(Fulfillment.class);
Criteria c = criteria.createCriteria("parent").createCriteria("parent")
.add(Expression.eq("orderID", new Long(11704)));
AppUtils.LOG.fatal("size["+criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list().size()+"]");
This criteria query work with hibernate 3.1. When I run this criteria using the annotation configuration, I get the following sql in the log:
Code:
from bo_order this_
inner join bo_order abstractor2_ on this_.parent=abstractor2_.orderID
inner join bo_order abstractor3_ on abstractor2_.parent=abstractor3_.orderID
where this_.type='F'
and abstractor3_.orderID=?
When I run this same exact query in 404GA-JEMS, I get a similar query. The only difference is that the second inner join is generated twice?
Code:
from bo_order this_
inner join bo_order abstractor2_ on this_.parent=abstractor2_.orderID
inner join bo_order abstractor3_ on abstractor2_.parent=abstractor3_.orderID <-- duplicate join
inner join bo_order abstractor3_ on abstractor2_.parent=abstractor3_.orderID <-- duplicate join
where this_.type='F'
and abstractor3_.orderID=?
And of course that is throwing a SQL error in MySQL (5.0).
The relevant mappings are:
Code:
@Entity
@DiscriminatorValue("F")
public class Fulfillment extends AbstractOrder {
<snip all properties - no relationships here>
}
@Entity
@DiscriminatorValue("F")
public class Invoice extends AbstractOrder {
<snip all properties - no relationships here>
}
@Entity
@DiscriminatorValue("F")
public class Sale extends AbstractOrder {
<snip all properties - no relationships here>
}
Code:
@Entity
@Table(name="order")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=1)
@EntityListeners(Audit.class)
public abstract class AbstractOrder implements IOrder {
@ManyToOne(fetch=FetchType.LAZY, targetEntity=AbstractOrder.class)
@JoinColumn(name="parent")
public IOrder getParent(){
return parent;
}
public void setParent(IOrder parent){
this.parent = parent;
}
@OneToMany(targetEntity=AbstractOrder.class, cascade=CascadeType.ALL, mappedBy="parent")
public Set getOrders(){
return orders;
}
public void setOrders(Set orders){
this.orders = orders;
}
public void addChildOrder(IOrder order){
order.setParent(this);
orders.add(order);
}
}
Any thoughts, even if on how to debug this further, would be much appreciated.
Thanks,
Chris....