Hi all!
Second post of the night as I still have problems.
Basically I want to "filter" a Set from loaded objects. For each period a consultant has a number of questionnaires. When I call
Code:
consultant.getQuestionnaires()
I only want the questionnaires related to a specific period.
I have been reading the reference guide and some posts but I still have problems only getting the desired result.
The relations between the tables are as follows:
Consultant 1 <--> * Questionnaire <one-many>
Questionnaire * <--> 1 ConsultantLevelQuestionnaire <many-to-one>
ConsultantLevelQuestionnaire * <--> 1 QuestionnairePeriod <many-to-one>
Is there a nice way to get only the questionnaires related to a specific period. Or do I need to manually set this? Any help is greatly appreciated!
Thanks in advance for the help!
Best regards,
Joakim
Consultant 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.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 [/code]