[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2571) Evaluating criteria expression with property of type Class throws "Unsupported discriminator type" exception

Tim Vasil (JIRA) noreply at atlassian.com
Mon Apr 16 14:18:04 EDT 2007


Evaluating criteria expression with property of type Class throws "Unsupported discriminator type" exception
------------------------------------------------------------------------------------------------------------

                 Key: HHH-2571
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2571
             Project: Hibernate3
          Issue Type: Bug
          Components: query-criteria
    Affects Versions: 3.2.3, 3.2.2, 3.2.4
         Environment: 3.2.3, Oracle
            Reporter: Tim Vasil
            Priority: Minor


Here's a sample mapping:
	<class name="Event" table="tbl_event">
		<id name='id' column='objid'>
		            <generator class="sequence">
		                <param name="sequence">event_id_seq</param>
		            </generator>
		</id>
		<version name='version' column='version'/>
		<property name="timestamp" column="timestamp" not-null="true" />
		<property name="sourceObjectClass" column="source_object_class" type="Class"/>
	</class>

Here's the criteria query I tried to execute:
	Criteria oCriteria = session.createCriteria(Event.class);
	oCriteria.add(Expression.eq("sourceObjectClass", czTargetClass));
	oCriteria.list();

If and only if czTargetClass is a class that is mapped (such as Event.class, or any other class in the mapping file), a QueryException("Unsupported discriminator type " + type) exception is thrown in CriteriaQueryTranslator.java.

This is a regression; the technique used to work in Hibernate 2 but broke when support for querying with discriminator types was added in Hibernate 3.

You can see in CriteraQueryTranslator.getTypedValue() that when a value of type Class is passed in and SessionFactoryHelper.findQueryableUsingImports() returns a non-null value, the code assumes it must be a discriminator value.  This is not necessarily the case, though, as you can see in this example.

The workaround I'm employing currently is to create a user-defined type that works like Hibernate's built-in ClassType but is able to query for classes based on String values in addition to Class values.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list