-->
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.  [ 9 posts ] 
Author Message
 Post subject: one-to many relation won't run SELECT query
PostPosted: Tue May 18, 2004 4:38 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hey,

I have 2 tables CustomerOrder and CustomerOrderLines. When I run my select query a get the following fault:

net.sf.hibernate.QueryException: path expression ends in a composite value: customeror0_.id [SELECT co.customerNo, co.status, co.deliveryDate, col.orderLineNo, col.articleNo, col.articleName, col.price, FROM net.sf.hibernate.CustomerOrder co, net.sf.hibernate.CustomerOrderLine col WHERE co.id=col.id.countryCode AND co.id=col.id.customerOrderNo col.orderLineNo='181382']

What does Hibernate mean with path expression ends in a composite value: customeror0_.id?

Mapping structure looks like this:

CustomerOrder
-----------------

Code:
       <composite-id name="compOrderLineID" class="net.sf.hibernate.CompositeCustOrdLinesID">
           <key-property name="customerOrderNo" column="CUSTOMERORDERNO" type="string"/>
           <key-property name="countryCode" column="COUNTRYCODE" type="string"/>
       </composite-id>
       
       <property name="deliveryDate" column="DELIVERYDATE"/>
        <property name="price" column="PRICE"/>
        <property name="freightCost" column="FREIGHTCOST"/>
        <property name="status" column="STATUS"/>
        <property name="paymentMode" column="PAYMENTMODE"/>
        <property name="totalVolume" column="TOTALVOLUME"/>
        <property name="totalWeight" column="TOTALWEIGHT"/>
        <property name="totalCost" column="TOTALCOST"/>
        <property name="versionNo" column="VERSIONNO"/>
    </class>



CustomerOrderLine
----------------------
Code:
    <class name="net.sf.hibernate.CustomerOrderLine" table="CUSTOMERORDERLINE_T">
   
      
      <composite-id name="compOrderLineID" class="net.sf.hibernate.CompositeCustOrdLinesID">
         <key-many-to-one name="customerOrderNo" class="net.sf.hibernate.CustomerOrder">
            <column name="countryCode"/>
            <column name="customerOrderNo"/>
         </key-many-to-one>
         <key-property name="orderLineNo" column="ORDERLINENO" type="string"/>
      </composite-id>
      
      
        <property name="articleNo" column="ARTICLENO"/>
        <property name="articleName" column="ARTICLENAME"/>
        <property name="quantity" column="QUANTITY"/>
        <property name="price" column="PRICE"/>
        <property name="volume" column="VOLUME"/>
        <property name="weight" column="WEGHT"/>
        <property name="deliveryDate" column="DELIVERYDATE"/>
    </class>


Best Regards

Johan


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:28 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
What's the actual query you are running? The SQL it's trying to query with doesn't look correct at all...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:59 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hey,

This the original query.


Code:
Query q = session.createQuery("SELECT co.customerNo, co.status, co.deliveryDate, col.orderLineNo, col.articleNo, col.articleName, col.price, " +
      "FROM net.sf.hibernate.CustomerOrder co, net.sf.hibernate.CustomerOrderLine col " +
      "WHERE co.id=col.id.countryCode AND co.id=col.id.customerOrderNo col.orderLineNo='181382'");


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 6:23 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Ok I can see two things wrong initially with the query syntax -

Query q = session.createQuery("SELECT co.customerNo, co.status, co.deliveryDate, col.orderLineNo, col.articleNo, col.articleName, col.price," +
"FROM
net.sf.hibernate.CustomerOrder co, net.sf.hibernate.CustomerOrderLine col " +
"WHERE co.id=col.id.countryCode AND co.id=col.id.customerOrderNo col.orderLineNo='181382'");

Firstly you have a trailing comma after col.price, which occurs before your FROM - not sure what effect this will have, but best delete it anyway. Secondly you are missing an AND in front of col.orderLineNo.

I'm not sure you should be trying to compare your composite IDs in the way you are either - just try co.id=col.id instead of comparing each column in the ID. I'm pretty sure Hibernate will work out the comparison correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:17 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
none of it worked. I still don't get the query to run. My 2 classes are these:

CustomerOrder
------------------

Code:
public class CustomerOrder implements Serializable {
   private Date createDate;
   private Date deliveryDate;
   private int price;
   private int freightCost;   
   private int status;
   private int paymentMode;
   private int totalVolume;
   private int totalWeight;
   private int totalCost;
   private int versionNo;
   private CustomerOrderId customerOrderId;
   public CustomerOrderLine[] orderLines;  // array containing orderLines
   

   

   /**
    * Returns the createDate.
    * @return Date
    */
   public Date getCreateDate() {
      return createDate;
   }

   /**
    * Returns the deliveryDate.
    * @return Date
    */
   public Date getDeliveryDate() {
      return deliveryDate;
   }

   /**
    * Returns the freightCost.
    * @return int
    */
   public int getFreightCost() {
      return freightCost;
   }

   /**
    * Returns the paymentMode.
    * @return int
    */
   public int getPaymentMode() {
      return paymentMode;
   }

   /**
    * Returns the price.
    * @return int
    */
   public int getPrice() {
      return price;
   }

   /**
    * Returns the status.
    * @return int
    */
   public int getStatus() {
      return status;
   }

   /**
    * Returns the totalCost.
    * @return int
    */
   public int getTotalCost() {
      return totalCost;
   }

   /**
    * Returns the totalWeight.
    * @return int
    */
   public int getTotalWeight() {
      return totalWeight;
   }

   /**
    * Returns the totalVolume.
    * @return int
    */
   public int getTotalVolume() {
      return totalVolume;
   }

   /**
    * Returns the versionNo.
    * @return int
    */
   public int getVersionNo() {
      return versionNo;
   }


   /**
    * Sets the createDate.
    * @param createDate The createDate to set
    */
   public void setCreateDate(Date createDate) {
      this.createDate = createDate;
   }

   /**
    * Sets the deliveryDate.
    * @param deliveryDate The deliveryDate to set
    */
   public void setDeliveryDate(Date deliveryDate) {
      this.deliveryDate = deliveryDate;
   }

   /**
    * Sets the freightCost.
    * @param freightCost The freightCost to set
    */
   public void setFreightCost(int freightCost) {
      this.freightCost = freightCost;
   }

   /**
    * Sets the paymentMode.
    * @param paymentMode The paymentMode to set
    */
   public void setPaymentMode(int paymentMode) {
      this.paymentMode = paymentMode;
   }

   /**
    * Sets the price.
    * @param price The price to set
    */
   public void setPrice(int price) {
      this.price = price;
   }

   /**
    * Sets the status.
    * @param status The status to set
    */
   public void setStatus(int status) {
      this.status = status;
   }

   /**
    * Sets the totalCost.
    * @param totalCost The totalCost to set
    */
   public void setTotalCost(int totalCost) {
      this.totalCost = totalCost;
   }

   /**
    * Sets the totalWeight.
    * @param totalWeight The totalWeight to set
    */
   public void setTotalWeight(int totalWeight) {
      this.totalWeight = totalWeight;
   }

   /**
    * Sets the totalVolume.
    * @param totalVolume The totalVolume to set
    */
   public void setTotalVolume(int totalVolume) {
      this.totalVolume = totalVolume;
   }

   /**
    * Sets the versionNo.
    * @param versionNo The versionNo to set
    */
   public void setVersionNo(int versionNo) {
      this.versionNo = versionNo;
   }

   /**
    * Returns the orderLines.
    * @return CustomerOrderLine
    */
   public CustomerOrderLine[] getOrderLines() {
      return orderLines;
   }

   /**
    * Sets the orderLines.
    * @param orderLines The orderLines to set
    */
   public void setOrderLines(CustomerOrderLine[] orderLines) {
      this.orderLines = orderLines;
   }

   /**
    * Returns the customerOrderId.
    * @return CustomerOrderId
    */
   public CustomerOrderId getCustomerOrderId() {
      return customerOrderId;
   }

   /**
    * Sets the customerOrderId.
    * @param customerOrderId The customerOrderId to set
    */
   public void setCustomerOrderId(CustomerOrderId customerOrderId) {
      this.customerOrderId = customerOrderId;
   }

}


CustomerOrderLine
----------------------

Code:
public class CustomerOrderLine implements Serializable {
   private String articleNo;
   private String articleName;
   private int quantity;
   private int price;
   private int volume;
   private int weight;   
   private int deliveryDate;
   private CustomerOrderLineId customerOrderLineId;
   

   

   /**
    * Returns the articleName.
    * @return String
    */
   public String getArticleName() {
      return articleName;
   }

   /**
    * Returns the articleNo.
    * @return String
    */
   public String getArticleNo() {
      return articleNo;
   }

   

   /**
    * Returns the deliveryDate.
    * @return int
    */
   public int getDeliveryDate() {
      return deliveryDate;
   }

   /**
    * Returns the price.
    * @return int
    */
   public int getPrice() {
      return price;
   }

   /**
    * Returns the quantity.
    * @return int
    */
   public int getQuantity() {
      return quantity;
   }

   /**
    * Returns the weight.
    * @return int
    */
   public int getWeight() {
      return weight;
   }

   /**
    * Returns the volume.
    * @return int
    */
   public int getVolume() {
      return volume;
   }

   /**
    * Sets the articleName.
    * @param articleName The articleName to set
    */
   public void setArticleName(String articleName) {
      this.articleName = articleName;
   }

   /**
    * Sets the articleNo.
    * @param articleNo The articleNo to set
    */
   public void setArticleNo(String articleNo) {
      this.articleNo = articleNo;
   }



   /**
    * Sets the deliveryDate.
    * @param deliveryDate The deliveryDate to set
    */
   public void setDeliveryDate(int deliveryDate) {
      this.deliveryDate = deliveryDate;
   }

   /**
    * Sets the price.
    * @param price The price to set
    */
   public void setPrice(int price) {
      this.price = price;
   }

   /**
    * Sets the quantity.
    * @param quantity The quantity to set
    */
   public void setQuantity(int quantity) {
      this.quantity = quantity;
   }

   /**
    * Sets the weight.
    * @param weight The weight to set
    */
   public void setWeight(int weight) {
      this.weight = weight;
   }

   /**
    * Sets the volume.
    * @param volume The volume to set
    */
   public void setVolume(int volume) {
      this.volume = volume;
   }



   /**
    * Returns the customerOrderLineId.
    * @return CustomerOrderLineId
    */
   public CustomerOrderLineId getCustomerOrderLineId() {
      return customerOrderLineId;
   }

   /**
    * Sets the customerOrderLineId.
    * @param customerOrderLineId The customerOrderLineId to set
    */
   public void setCustomerOrderLineId(CustomerOrderLineId customerOrderLineId) {
      this.customerOrderLineId = customerOrderLineId;
   }
}


Got any other suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:24 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Have a read of http://opensource.atlassian.com/projects/hibernate/browse/HB-109 - it seems there are some peculiarities when working with composite IDs and Hibernate.

Also searching the forums with your error pulls up a load of posts on the same issue. You might want to have a look at them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:44 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Okey,

There was some interesting points at the link. But what your're saying is that Hibernate today don't support a situation where the relation is 1-to-Many and both involved classes/tables uses 2 or more keys (foreign keys)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:46 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
..sorry, I mean composite keys


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:53 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
I'm not saying that Hibernate doesn't support the set-up you have, I'm saying that I don't know.

There appears to be a lack of depth to the composite ID support, reading that JIRA issue, but since I don't use them I'm afraid I can't comment either way.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.