-->
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.  [ 6 posts ] 
Author Message
 Post subject: Links not being recognised in query.
PostPosted: Tue Sep 26, 2006 1:15 pm 
Newbie

Joined: Thu Aug 31, 2006 7:56 am
Posts: 14
I am using Hibernate-Version: 3.2.0.cr4 with SQL Server 2000, in a Tomcat 5.5.16 app with JDK 1.5.0_06.

I wish to retrieve the Orders for a given Rep, and force the immediate retrieval of the Rep records as well. I have sucessfully retrieved all Orders with their associated Reps (lazily) with the HQL
Code:
"from Order order"



This code

Code:
  public static List loadOrders(String repCode)
  {
    Session session = HibernateUtil.getSession();

    Query q = session.createQuery(
        "from Order order left join fetch order.rep where rep.code > :repCode");
    q.setParameter("repCode", repCode);
   
    return q.list();
  }


gives rise to the following error:

Code:
org.hibernate.QueryException: could not resolve property: rep of: com.myco.Order [from com.myco.Order di left join fetch di.rep where rep.code > :repCode]


The mappings have been created via the Eclipse Hibernate plugin and, as I said above, I can retrieve the orders and then navidate to the referenced Rep objects.

p.s. I have attempted to do the same using Criteria, but get the same result.

---------------------------------------------------------
Order extends the following generated class

Code:
package com.myco.base;

import java.io.Serializable;


public abstract class BaseOrder  implements Serializable {

  ..
  ..

   // constructors
   public BaseOrder () {
      initialize();
   }

   /**
    * Constructor for primary key
    */
   public BaseOrder (java.lang.Long id) {
      this.setId(id);
      initialize();
   }

  ..
  ..

   protected void initialize () {}



   private int hashCode = Integer.MIN_VALUE;

   // primary key
   private java.lang.Long id;

   // fields
   private java.lang.String order;
   ..
  ..
   // many to one
   private com.myco.Rep rep;

   ..
  ..

   /**
    * Return the value associated with the column: repId
    */
   public com.taylodge.commission.Rep getRep () {
      return rep;
   }

   /**
    * Set the value related to the column: repId
    * @param rep the repId value
    */
   public void setRep (com.taylodge.commission.Rep rep) {
      this.rep = rep;
   }

   ..
  ..

}

------------------------------------------------------------------------------------
Mapping file

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.myco">
   <class
      name="Order"
      table="Order"
   >
      <meta attribute="sync-DAO">false</meta>


      <id
         name="Id"
         type="java.lang.Long"
         column="id"
         unsaved-value="null"
      >
         <generator class="increment"/>
      </id>

      <!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
      <property
         name="Order"
         column="order"
         type="java.lang.String"
         not-null="true"
         length="20"
      />

      ..
      ..
      
      <many-to-one
         name="Rep"
         column="repId"
         class="Rep"
         not-null="true"
      >
      </many-to-one>
   </class>   
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Query syntax
PostPosted: Tue Sep 26, 2006 1:56 pm 
Newbie

Joined: Tue Sep 12, 2006 7:03 am
Posts: 7
Location: Berlin
Quote:
"from Order order left join fetch order.rep where rep.code > :repCode"


Did you try
Code:
"from Order order left join fetch order.rep where order.rep.code > :repCode"

?

Fritz


Top
 Profile  
 
 Post subject: Re: Query syntax
PostPosted: Tue Sep 26, 2006 2:21 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
fritz wrote:
Quote:
"from Order order left join fetch order.rep where rep.code > :repCode"



Code:
from Order order left join fetch order.rep report where report.code > :repCode


Top
 Profile  
 
 Post subject: Re: Query syntax
PostPosted: Wed Sep 27, 2006 3:22 am 
Newbie

Joined: Thu Aug 31, 2006 7:56 am
Posts: 14
fritz wrote:
Did you try
Code:
"from Order order left join fetch order.rep where order.rep.code > :repCode"

?

Fritz


Yes, I have tried that and I got exactly the same error.


Top
 Profile  
 
 Post subject: Re: Query syntax
PostPosted: Wed Sep 27, 2006 3:30 am 
Newbie

Joined: Thu Aug 31, 2006 7:56 am
Posts: 14
rajasaur wrote:

Code:
from Order order left join fetch order.rep report where report.code > :repCode


Tried this as well, no joy. Thanks for thr effort.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 27, 2006 4:14 am 
Newbie

Joined: Thu Aug 31, 2006 7:56 am
Posts: 14
Problem solved. I did not realise that HQL was case sensitive. As soon as I changed the names to match the case of the mapping file, it worked...i.e.
Code:
from Order order left join fetch order.Rep where order.Rep.Code > :repCode


btw, the following worked also..

Code:
from Order order left join fetch order.Rep report where report.Code > :repCode


Both replies helped in the solution, thanks guys, much appreciated.


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