-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Recursive Relationship Generating Duplicate From Table
PostPosted: Wed Nov 15, 2006 4:20 am 
Beginner
Beginner

Joined: Tue Sep 09, 2003 9:11 pm
Posts: 32
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....

_________________
___________
Chris....
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try the latest hibernate core version and if it still fails, post a minimal test case to JIRA so that we don't forget it

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.