| Hello,
I have the following object model in which various "type" classes (BooleanAttribute, DateAttribute, etc.) subclass from an AbstractAttribute class.  The subclasses store their values in type-specific columns through the use of a discriminator.  I'm trying to construct an HQL query where I'm returning BooleanAttributes whose value is "true".  The problem is that even if I include a ".class=" statement in the where-clause, Hibernate still seems to want to return the "string_value" column (causing a SQL error) instead of the "boolean_value" column.  How do I force it to return the "boolean_value" column for the comparison?  Is there a "cast" that I can perform?  Details below.
 Thanks!
 
 Hibernate version: 3.1.3
 
 Mapping documents:
 
 Relevant Portion:
 <discriminator column="discriminator" type="string"/>
 <subclass name="com.attribute.model.StringAttribute" discriminator-value="STR">
 <property name="value" column="string_value" type="string"/>
 </subclass>
 <subclass name="com.attribute.model.FloatAttribute" discriminator-value="FLT">
 <property name="value" column="float_value" type="float"/>
 </subclass>
 <subclass name="com.attribute.model.LongAttribute" discriminator-value="LNG">
 <property name="value" column="long_value" type="long"/>
 </subclass>
 <subclass name="com.attribute.model.IntegerAttribute" discriminator-value="INT">
 <property name="value" column="integer_value" type="integer"/>
 </subclass>
 <subclass name="com.attribute.model.BooleanAttribute" discriminator-value="BOO">
 <property name="value" column="boolean_value" type="boolean"/>
 </subclass>
 <subclass name="com.attribute.model.DateAttribute" discriminator-value="DAT">
 <property name="value" column="date_value" type="date"/>
 </subclass>
 <subclass name="com.attribute.model.CurrencyAttribute" discriminator-value="CUR">
 <property name="value" column="float_value" type="float"/>
 </subclass>
 
 Code between sessionFactory.openSession() and session.close():
 
 Relevant Portion:
 queryStr += (" and a3.attributeDefinition.name='" + Constants.PRODUCT_ATTRIBUTE_NAME_NEWMEDIA + "' and a3.class=com.attribute.model.BooleanAttribute and a3.value=true");
 
 Full stack trace of any exception that occurs:
 
 org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select distinct product0_.product_id as product1_20_, product0_.edition_id as edition2_20_, product0_.product_number as product3_20_, product0_.parent_source_product_id as parent4_20_, product0_.group_type_id as group5_20_, product0_.created_date as created6_20_, product0_.created_by as created7_20_, product0_.modified_date as modified8_20_, product0_.modified_by as modified9_20_ from product product0_ inner join relationship relationsh1_ on product0_.product_id=relationsh1_.product_id inner join abstract_attribute attributes2_ on relationsh1_.relationship_id=attributes2_.relationship_id inner join relationship relationsh3_ on product0_.product_id=relationsh3_.product_id inner join node node4_ on relationsh3_.node_id=node4_.node_id inner join relationship relationsh5_ on product0_.product_id=relationsh5_.product_id inner join node node6_ on relationsh5_.node_id=node6_.node_id inner join relationship relationsh7_ on product0_.product_id=relationsh7_.product_id inner join abstract_attribute attributes8_ on relationsh7_.relationship_id=attributes8_.relationship_id inner join relationship relationsh9_ on product0_.product_id=relationsh9_.product_id inner join abstract_attribute attributes10_ on relationsh9_.relationship_id=attributes10_.relationship_id, attribute_definition attributed11_ where attributes10_.attribute_definition_id=attributed11_.attribute_definition_id and attributed11_.name='newMedia' and attributes10_.discriminator='BOO' and attributes10_.string_value=true]; nested exception is org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = boolean
 
 Name and version of the database you are using: Postgres 8.1
 
 
 |