Hi all!
Im pretty much a newbie and are having problem with a table join involving <one-to-many> relationships
The following HQL (1) works just fine but not the second (2)
First (1):
FROM C c, Q q
WHERE q in elements(c.questionnaires)
AND q.consultantLevelQuestionnaire.period=:period
- works just fine
Second (2):
FROM Consultant c
WHERE :period in elements(c.questionnaires.consultantLevelQuestionnaire.period)
(2) returns - org.hibernate.QueryException: could not resolve property: period of: test.evalLight.Questionnaire [FROM test.evalLight.Consultant c
WHERE :period in
(c.questionnaires.consultantLevelQuestionnaire.period)
]
If I replace c.questionnaires.levelQuestionnaire.period with period.id i get a null pointer
The thing is that I have not fully understood is how to make joins when using Sets. I would like (2) to work because it only returns one Set of data. Do i need to write this HQL as (1) or is it a better way of improving (2) to have it work.
Thanks in advance for the help
Best regards,
Joakim
Consultant mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2005-dec-16 12:21:47 by Hibernate Tools 3.1.0 beta1JBIDERC2 -->
<hibernate-mapping>
<class name="test.evalLight.Consultant" table="Konsult">
<id name="id" type="int" unsaved-value="0">
<column name="KonsultID" />
<generator class="native" />
</id>
<set name="questionnaires" inverse="true">
<key>
<column name="IfyllandeKonsultID" not-null="true" />
</key>
<one-to-many class="test.evalLight.Questionnaire" />
</set>
<set name="targetQuestionnaires" inverse="true" fetch="join">
<key>
<column name="GällerKonsultID" not-null="true" />
</key>
<one-to-many class="test.evalLight.Questionnaire" />
</set>
</class>
</hibernate-mapping>
Questionnaire MappingCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2005-dec-16 12:21:47 by Hibernate Tools 3.1.0 beta1JBIDERC2 -->
<hibernate-mapping>
<class name="test.evalLight.Questionnaire" table="Enkätifyllning">
<id name="id" type="integer">
<column name="EnkätifyllningID" />
<generator class="native" />
</id>
<many-to-one name="targetConsultant" class="test.evalLight.Consultant" fetch="select">
<column name="GällerKonsultID" not-null="true" />
</many-to-one>
<many-to-one name="consultant" class="test.evalLight.Consultant" fetch="select">
<column name="IfyllandeKonsultID" not-null="true" />
</many-to-one>
<many-to-one name="consultantLevelQuestionnaire" class="test.evalLight.ConsultantLevelQuestionnaire" fetch="select">
<column name="EnkätID" not-null="true" />
</many-to-one>
<set name="data" inverse="true">
<key>
<column name="EnkätifyllningID" not-null="true" />
</key>
<one-to-many class="test.evalLight.QuestionnaireData" />
</set>
</class>
</hibernate-mapping>
ConsultantLevelQuestionnaire MappingCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2005-dec-16 12:21:47 by Hibernate Tools 3.1.0 beta1JBIDERC2 -->
<hibernate-mapping>
<class name="test.evalLight.ConsultantLevelQuestionnaire" table="Enkät">
<id name="id" type="integer">
<column name="EnkätID" />
<generator class="native" />
</id>
<many-to-one name="period" class="test.evalLight.QuestionnairePeriod" fetch="select">
<column name="EnkätomgångID" not-null="true" />
</many-to-one>
<many-to-one name="consultantLevel" class="test.evalLight.ConsultantLevel" fetch="select">
<column name="KonsultnivåID" not-null="true" />
</many-to-one>
<property name="name" type="string">
<column name="EnkätNamn" length="50" not-null="true" />
</property>
<property name="created" type="timestamp">
<column name="Skapad" length="16" not-null="true" />
</property>
<set name="questionnaires" inverse="true">
<key>
<column name="EnkätID" not-null="true" />
</key>
<one-to-many class="test.evalLight.Questionnaire" />
</set>
</class>
</hibernate-mapping>
QuestionnairePeriod MappingCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2005-dec-16 12:21:47 by Hibernate Tools 3.1.0 beta1JBIDERC2 -->
<hibernate-mapping>
<class name="test.evalLight.QuestionnairePeriod" table="Enkätomgång">
<id name="id" type="integer">
<column name="EnkätomgångID" />
<generator class="native" />
</id>
<property name="name" type="string">
<column name="EnkätomgångNamn" length="50" not-null="true" />
</property>
<set name="consultantLevelQuestionnaires" inverse="true" order-by="KonsultnivåID asc">
<key>
<column name="EnkätomgångID" not-null="true" />
</key>
<one-to-many class="test.evalLight.ConsultantLevelQuestionnaire" />
</set>
</class>
</hibernate-mapping>
Hibernate version:3.0.5