Hello,
I've got a problem with Hibernate 2.1.1
HQL that works:
Quote:
select count(ce) from CategoryEntry as ce +
inner join ce.category as с +
where ce.category.id = ?
The generated SQL is as follows:
Quote:
select count(categoryen0_.ID) as x0_0_ from Category_Entry categoryen0_ inner join Category category1_ on categoryen0_.category_id=category1_.ID where (category1_.ID=? )
Now if I try to use alias
c, like this:
Quote:
select count(ce) from CategoryEntry as ce +
inner join ce.category as с +
where c.id = ?
The generated SQL becomes:
Quote:
select count(categoryen0_.ID) as x0_0_ from Category_Entry categoryen0_ inner join Category category1_ on categoryen0_.category_id=category1_.ID where (c.id=? )
Obviously this SQL won't work. So what I am doing wrong?
HBMs:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ru.extram.customerpublishing.infobag.dal.Category" table="Category">
<id column="ID" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="name" length="100" name="name" type="java.lang.String"/>
<property column="description" length="500" name="description" type="java.lang.String"/>
<property column="is_leaf" length="1" name="isLeaf" type="java.lang.Boolean"/>
<property column="order_number" length="10" name="orderNumber" type="java.lang.Integer"/>
<property column="xml_name" length="100" name="xmlName" type="java.lang.String"/>
<property column="alias_category_id" length="10" name="aliasCategoryId" type="java.lang.Integer"/>
<property column="parent_category_id" length="10" name="parentCategoryId" type="java.lang.Integer"/>
<property column="category_type_id" length="10" name="categoryTypeId" type="java.lang.Integer"/>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ru.extram.customerpublishing.infobag.dal.CategoryEntry" table="Category_Entry">
<id column="ID" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="category_id" insert="false" update="false" length="10" name="categoryId" not-null="true" type="java.lang.Integer"/>
<property column="entry_id" insert="false" update="false" length="10" name="entryId" not-null="true" type="java.lang.Integer"/>
<property column="int_value" length="10" name="intValue" type="java.lang.Integer"/>
<property column="FloatValue" length="53" name="floatvalue" type="java.lang.Float"/>
<property column="DateValue" length="23" name="datevalue" type="java.util.Date"/>
<property column="MoneyValue" length="19" name="moneyvalue" type="java.lang.Double"/>
<property column="image_id" length="10" name="imageId" type="java.lang.Integer"/>
<many-to-one name="category" class="ru.extram.customerpublishing.infobag.dal.Category" column="category_id" not-null="true"/>
<many-to-one name="entry" class="ru.extram.customerpublishing.infobag.dal.Entry" column="entry_id" not-null="true"/>
<set name="stringValues" lazy="true" cascade="all">
<key column="category_entry_id"/>
<one-to-many class="ru.extram.customerpublishing.infobag.dal.StringValue"/>
</set>
</class>
</hibernate-mapping>