-->
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: SQL Grammer error, missing linkage table
PostPosted: Wed Oct 25, 2006 1:21 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Hibernate version: 3.1.3

Mapping documents:
Code:
<class name="com.company.RecurInsnHead" table="recur_insn_head">
      <id name="recurInsnId" type="long" column="recur_insn_id">
         <generator class="native" />
      </id>

      <many-to-one name="salesCustomer"        not-null="true"                   column="sales_customer_id" />
      <property    name="salesCustomerAccount" not-null="false" type="long"      column="sales_customer_account" />
      <property    name="costingCode"          not-null="true"  type="char"      column="costing_code" />
      <many-to-one name="productLine"          not-null="true"                   column="product_line_id" />
      <many-to-one name="productDetail"        not-null="true"                   column="product_detail_id" />
      <property    name="whenServiceSunrise"   not-null="true"  type="timestamp" column="when_service_sunrise" />
      <property    name="whenServiceSunset"    not-null="false" type="timestamp" column="when_service_sunset" />
      <property    name="description"          not-null="false" type="string"    column="description" />
      <property    name="reference"            not-null="false" type="integer"   column="reference" />
</class>

<class name="com.company.ProductDetail" table="product_detail">
      <id name="productDetailId" type="long" column="product_detail_id">
         <generator class="native" />
      </id>

      <many-to-one name="productLine"  not-null="true"       column="product_line_id" />
      
      <map name="attributes" table="product_detail_attrs" cascade="all">
         <key column="product_detail_id" not-null="true"/>
         <map-key column="name" type="string"/>
         <element column="value" not-null="true" type="string" />
      </map>
</class>


Name and version of the database you are using: MySQL 4.1.x

The generated SQL (show_sql=true):
Code:
This is my HQL query:
SELECT rec FROM com.company.RecurInsnHead AS rec WHERE rec.salesCustomer=? AND rec.productLine=? AND rec.productDetail.attributes[?]=?

These are my HQL parameters:
PARAM: ('com.company.SalesCustomer@183e895', 'com.company.ProductLine@1386751', 'KEY', 'value')

Hibernate: select recurinsnh0_.recur_insn_id as recur1_25_,
recurinsnh0_.sales_customer_id as sales2_25_,
recurinsnh0_.sales_customer_account as sales3_25_,
recurinsnh0_.costing_code as costing4_25_,
recurinsnh0_.product_line_id as product5_25_,
recurinsnh0_.product_detail_id as product6_25_,
recurinsnh0_.when_service_sunrise as when7_25_,
recurinsnh0_.when_service_sunset as when8_25_,
recurinsnh0_.description as descript9_25_,
recurinsnh0_.reference as reference25_
from recur_insn_head recurinsnh0_,
product_detail_attrs attributes2_
where productdet1_.product_detail_id=attributes2_.product_detail_id
and attributes2_.name = ?
and recurinsnh0_.product_detail_id=productdet1_.product_detail_id
and recurinsnh0_.sales_customer_id=?
and recurinsnh0_.product_line_id=?
and attributes2_.value=?

WARN  25-10 09:46:36,618 (JDBCExceptionReporter.java:logExceptions:71)  -SQL Error: 1109, SQLState: 42S02
ERROR 25-10 09:46:36,621 (JDBCExceptionReporter.java:logExceptions:72)  -Unknown table 'productdet1_' in where clause


As you can see above the there is no FROM clause for "product_detail productdet1_" which links the Java object graph:

rec.getProductDetail().getAttributes().get('KEY')

Where:
rec = com.company.RecurInsnHead (persisted in table recur_insn_head)
rec.getProductDetail() = com.company.ProductDetail (persisted in table product_detail)
rec.getProductDetail.getAttributes() = java.util.Map<String,String> (persisted in table product_detail_attrs)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 2:20 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Tested with 3.2 GA, same grammer error.

I have worked around the issue by implementing the getAttributes().get('KEY').equals('value') filter in Java:

Code:
            List<RecurInsnHead> list = (List<RecurInsnHead>) q.list();
            Iterator it = list.iterator();
            while(it.hasNext()) {
               RecurInsnHead r = (RecurInsnHead) it.next();
               if(key != null) {
                  String v = (String) r.getProductDetail().getAttributes().get(key);
                  if(v == null || v.compareTo(value) != 0) {
                     it.remove();
                  }
               }
            }


Maybe someone could confirm if this is an error and who is a fault (me or hibernate). As a user I would think that any valid/accepted HQL syntax should always generate valid SQL.


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.