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)