Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.8
Mapping documents:
<?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="com.mandaladesigns.service.MDXGroup"
table="MDX_GROUP"
dynamic-update="true"
dynamic-insert="true"
select-before-update="false"
optimistic-lock="version"
discriminator-value="MDX_GROUP"
>
<id
name="identifier"
column="ID"
type="java.lang.Integer"
unsaved-value="0"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-MDXGroup.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="DISCRIMINATOR"
type="string"
force="false"
/>
<many-to-one
name="parent"
class="com.mandaladesigns.service.MDXGroup"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="PARENT_ID"
/>
<set
name="children"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
order-by="SEQUENCE"
where="ID != PARENT_ID"
>
<key
column="PARENT_ID"
>
</key>
<one-to-many
class="com.mandaladesigns.service.MDXGroup"
/>
</set>
<many-to-one
name="groupType"
class="com.mandaladesigns.service.ListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="GROUP_TYPE_LE_ID"
not-null="true"
/>
<property
name="shortDescription"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="SHORT_DESCRIPTION"
/>
<property
name="longDescription"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="LONG_DESCRIPTION"
/>
<property
name="fullDescription"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="FULL_DESCRIPTION"
/>
<component
name="sourceLastModifiedDateTime"
class="com.mandaladesigns.service.MDXDateTime"
>
<property
name="dateTime"
type="timestamp"
update="true"
insert="true"
access="property"
>
<column
name="SOURCE_LAST_MODIFIED_DATE_TIME"
/>
</property>
<property
name="nano"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
>
<column
name="SOURCE_LAST_MODIFIED_NANO"
/>
</property>
</component>
<property
name="sequence"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="SEQUENCE"
/>
<many-to-one
name="createdByUser"
class="com.mandaladesigns.service.common.usermanagement.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="CREATED_BY_USER_ID"
/>
<many-to-one
name="lastModifiedByUser"
class="com.mandaladesigns.service.common.usermanagement.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="LAST_MODIFIED_BY_USER_ID"
/>
<property
name="dateCreated"
type="timestamp"
update="true"
insert="true"
access="property"
column="DATE_CREATED"
/>
<property
name="dateModified"
type="timestamp"
update="true"
insert="true"
access="property"
column="DATE_MODIFIED"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-MDXGroup.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.mandaladesigns.service.application.education.ImsGroup"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="IMS_GROUP"
>
<component
name="imsSourceDId"
class="com.mandaladesigns.service.ImsSourceDId"
>
<property
name="id"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="SOURCE_ID"
/>
</property>
</component>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ImsGroup.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.mandaladesigns.service.application.education.AcademicCourseBase"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="ACADEMIC_COURSE_BASE"
>
<many-to-one
name="division"
class="com.mandaladesigns.service.ListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="AC_DIVISION_LE_ID"
/>
<many-to-one
name="institutionalDivision"
class="com.mandaladesigns.service.ListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="AC_INSTITUTIONAL_DIVISION_LE_ID"
/>
<property
name="courseCode"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="AC_COURSE_CODE"
/>
<property
name="creditHours"
type="java.math.BigDecimal"
update="true"
insert="true"
access="property"
column="AC_DEFAULT_CREDITS"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AcademicCourseBase.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.mandaladesigns.service.application.education.AcademicSection"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="ACADEMIC_SECTION"
>
<property
name="isWebEnhanced"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="ACS_IS_WEB_ENHANCED"
not-null="true"
/>
<many-to-one
name="crossListedParent"
class="com.mandaladesigns.service.application.education.AcademicSection"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="ACS_CROSS_LISTED_PARENT_ID"
/>
<component
name="courseDates"
class="com.mandaladesigns.service.MDXTimeFrame"
>
<property
name="beginDate"
type="timestamp"
update="true"
insert="true"
access="property"
>
<column
name="ACS_COURSE_BEGIN_DATE"
/>
</property>
<property
name="endDate"
type="timestamp"
update="true"
insert="true"
access="property"
>
<column
name="ACS_COURSE_END_DATE"
/>
</property>
</component>
<component
name="academicTerm"
class="com.mandaladesigns.service.application.education.AcademicTerm"
>
<many-to-one
name="year"
class="com.mandaladesigns.service.IngestibleListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="ACS_YEAR_LE_ID"
/>
</many-to-one>
<many-to-one
name="term"
class="com.mandaladesigns.service.IngestibleListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="ACS_TERM_LE_ID"
/>
</many-to-one>
<property
name="academicTermText"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="ACS_ACADEMIC_TERM_TEXT"
/>
</property>
</component>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AcademicSection.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="com.mandaladesigns.service.application.education.AcademicCourse"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="ACADEMIC_COURSE"
>
<property
name="maxEnrollment"
type="int"
update="true"
insert="true"
access="property"
column="AC_MAX_ENROLLMENT"
/>
<set
name="outcomes"
table="OUTCOME_ACADEMIC_COURSE_ASSOCIATION"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
column="ACADEMIC_COURSE_ID"
>
</key>
<many-to-many
class="com.mandaladesigns.service.application.education.outcomemanagement.outcomeportfolio.Outcome"
column="OUTCOME_ID"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AcademicCourse.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</subclass>
<subclass
name="com.mandaladesigns.service.application.education.outcomemanagement.outcomeportfolio.OutcomeBase"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="OUTCOME_BASE"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OutcomeBase.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.mandaladesigns.service.application.education.outcomemanagement.outcomeportfolio.OutcomePortfolio"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="OUTCOME_PORTFOLIO"
>
<property
name="isDefault"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="OP_IS_DEFAULT"
/>
<many-to-one
name="status"
class="com.mandaladesigns.service.ListElement"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="STATUS_TYPE_LE_ID"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OutcomePortfolio.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="com.mandaladesigns.service.application.education.outcomemanagement.outcomeportfolio.OutcomeGroup"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="OUTCOME_GROUP"
>
<property
name="minRequiredOutcomes"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="OG_MIN_REQUIRED_OUTCOMES"
/>
<property
name="maxRequiredOutcomes"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="OG_MAX_REQUIRED_OUTCOMES"
/>
<property
name="headlineRequiredOutcomes"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_HEADLINE_REQUIRED_OUTCOMES"
/>
<property
name="headlineOptionalOutcomes"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_HEADLINE_OPTIONAL_OUTCOMES"
/>
<property
name="additionalNotes"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="OG_ADDITIONAL_NOTES"
/>
<property
name="minRequiredCredits"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="OG_MIN_REQUIRED_CREDITS"
/>
<property
name="maxRequiredCredits"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="OG_MAX_REQUIRED_CREDITS"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OutcomeGroup.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="com.mandaladesigns.service.application.education.outcomemanagement.outcomeportfolio.Outcome"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="OUTCOME"
>
<property
name="isRequired"
type="java.lang.Boolean"
update="true"
insert="true"
access="property"
column="O_IS_REQUIRED"
/>
<property
name="furtherClarificationNote"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="O_FURTHER_CLARIFICATION_NOTE"
/>
<property
name="alsoMetByNote"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="O_ALSO_MET_BY_NOTE"
/>
<map
name="academicCoursesMap"
table="OUTCOME_ACADEMIC_COURSE_ASSOCIATION"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all"
>
<key
column="OUTCOME_ID"
>
</key>
<index-many-to-many
class="com.mandaladesigns.service.application.education.AcademicCourse"
column="ACADEMIC_COURSE_ID"
/>
<many-to-many
class="com.mandaladesigns.service.ListElement"
column="STATUS_LE_ID"
outer-join="auto"
/>
</map>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Outcome.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
Exception in thread "main" Error executing HQL: SELECT DISTINCT primaryObjectAlias FROM com.mandaladesigns.service.application.education.AcademicCourse as primaryObjectAlias left join primaryObjectAlias.children as academicSection WHERE academicSection.class = com.mandaladesigns.service.application.education.AcademicSection and academicSection.academicTerm.academicTermText >= '1999' : net.sf.hibernate.QueryException: could not resolve property: academicTerm of: com.mandaladesigns.service.MDXGroup [SELECT DISTINCT primaryObjectAlias FROM com.mandaladesigns.service.application.education.AcademicCourse as primaryObjectAlias left join primaryObjectAlias.children as academicSection WHERE academicSection.class = com.mandaladesigns.service.application.education.AcademicSection and academicSection.academicTerm.academicTermText >= '1999']
at com.mandaladesigns.service.system.persistence.HibernatePersistenceServiceImpl.performHQLQuery(HibernatePersistenceServiceImpl.java:433)
at com.mandaladesigns.manager.IngestManager$CommandEnum$2.execute(IngestManager.java:29)
at com.mandaladesigns.manager.IngestManager$CommandEnum.callIt(IngestManager.java:43)
at com.mandaladesigns.manager.IngestManager.main(IngestManager.java:58)
Caused by: net.sf.hibernate.QueryException: could not resolve property: academicTerm of: com.mandaladesigns.service.MDXGroup [SELECT DISTINCT primaryObjectAlias FROM com.mandaladesigns.service.application.education.AcademicCourse as primaryObjectAlias left join primaryObjectAlias.children as academicSection WHERE academicSection.class = com.mandaladesigns.service.application.education.AcademicSection and academicSection.academicTerm.academicTermText >= '1999']
at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at net.sf.hibernate.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:665)
at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:123)
at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:342)
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:374)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:259)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)
at com.mandaladesigns.service.system.persistence.HibernatePersistenceServiceImpl.performHQLQuery(HibernatePersistenceServiceImpl.java:431)
... 3 more
Name and version of the database you are using:
mysql Ver 14.7 Distrib 4.1.9, for pc-linux-gnu (i686)
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
Problem Description: I am attempting to perform a query on a class that has a polymorphic one-to-many association. I would like part of my query to search on a field that is in a subclass of the associated class and not in the mapped superclass.
I receive the error: "net.sf.hibernate.QueryException: could not resolve property: academicTerm of: com.mandaladesigns.service.MDXGroup" which leads me to believe that Hibernate will only allow me to query on fields of the superclass of the associated object that is mapped (MDXGroup) and not on fields of the concrete subclass that is returned.
Is there a way I can tell the query that in this case I know the concrete class of the associated objects so that I can query on the subclass's fields?
Or, is there a way for me to override the mapping of "children" in the AcademicCourse class and map them directly to AcademicSection objects rather than MDXGroup objects?
Am I missing something?
Here is the HQL:
SELECT DISTINCT primaryObjectAlias
FROM com.mandaladesigns.service.application.education.AcademicCourse as primaryObjectAlias left join primaryObjectAlias.children as academicSection
WHERE academicSection.class = com.mandaladesigns.service.application.education.AcademicSection
and academicSection.academicTerm.academicTermText >= '1999'
I am using table-per-hierarchy mapping using the table MDX_GROUP which is mapped to many classes, the superclass being MDXGroup. An MDXGroup can have children, who are linked back to the MDX_GROUP table through the foreign key PARENT_ID.
In the specific instance I'm working with, I am dealing with AcademicCourse objects who have children of AcademicSection objects. Both of these objects (and many others) extends from MDXGroup. I would like to perform an HQL query on AcademicCourse objects that search on fields that are unique to the child objects, AcademicSection. Since it is the superclass, MDXGroup, that maps the "children" one-to-many association I don't seem to be able to query on fields that aren't in MDXGroup.