Hello,
I am using Hibernate in an e-learning system to make learner models
persistent (extracts of the class definitions and mapping to a
relational model are included below). Development have been a bit
painful --since I am not and expert on databases nor the Hibernate
manual is particularly clear at points-- but have been moving for a
while: models can be stored and retrieved, as well as individual
beliefs. But now I am stuck with a particular query:
Code:
select {belief.*} from belief, bdesc
where belief.lmodel_id = 'JorgeNegrete'
and belief.bdesc_id = bdesc.id
and bdesc.competencyId = 'think'
(Not syntatically correct but gives you the idea)
I think it could be solved with HQL, but requires adding private fiels
to belief for lmodel_id and bdesc_id, yet I don't quite like this
approach. I tried SQL, but then I have problems understanding what the
arguments of addJoin are. Criteria search? Can't see how. Filters?
Haven't found examples with Map (instead of Set or List) I can adjust
to my case.
Please let me know if you have any suggestions.
Regards,
Rafael
Extracts of class definitionsCode:
public class LearnerModel {
String learnerId;
Map beliefs;
// ...
}
public class Belief {
private List evidence;
private int news;
MassDistribution massDist;
// ...
}
public class BeliefDescriptor {
private String metacogId;
private String motivationId;
private String affectId;
private String competencyId;
private String capeId;
private String domainId;
// ...
}
LearnerModel mappingCode:
<hibernate-mapping package="org.activemath.xlm.model">
<class name="LearnerModel" table="LModel">
<id name="learnerId" column="id">
<generator class="assigned"/>
</id>
<map name="beliefs" cascade="all,delete-orphan">
<key column="LModel_id" not-null="true" />
<map-key-many-to-many class="BeliefDescriptor" column="BDesc_id" />
<one-to-many class="Belief"/>
</map>
</class>
</hibernate-mapping>
Belief mapping:
Code:
<hibernate-mapping default-access="field"
package="org.activemath.xlm.model">
<class name="Belief" table="Belief" >
<id type="long">
<generator class="native" />
</id>
<component class="MassDistribution" name="massDist">
<primitive-array name="massDist" table="MassDist">
<key column="Belief_id"/>
<list-index column="lSetOrd"/>
<element column="bpa" type="double">
</element>
</primitive-array>
</component>
<list name="evidence" cascade="all,delete-orphan">
<key column="Belief_id" not-null="true"/>
<list-index column="n" />
<one-to-many class="Evidence"/>
</list>
</class>
</hibernate-mapping>
BeliefDescriptor mappingCode:
<hibernate-mapping>
<class name="org.activemath.xlm.model.BeliefDescriptor" lazy="false"
table="BDesc">
<id type="long" >
<generator class="native" />
</id>
<properties name="coordinates" unique="true">
<property name="metacogId" access="field" not-null="true"/>
<property name="motivationId" access="field" not-null="true"/>
<property name="affectId" access="field" not-null="true"/>
<property name="competencyId" access="field" not-null="true"/>
<property name="capeId" access="field" not-null="true"/>
<property name="domainId" access="field" not-null="true"/>
</properties>
</class>
</hibernate-mapping>
Evidence mappingCode:
<hibernate-mapping package="org.activemath.xlm.model">
<class name="Evidence" table="Evidence" >
<id type="long">
<generator class="native"/>
</id>
<property name="eventId" />
<component class="MassDistribution" name="mass" >
<primitive-array name="massDist" access="field"
table="EventInterp">
<key not-null="true" column="Evidence_id"/>
<list-index column="lSetOrd"/>
<element column="bpa" type="double" />
</primitive-array>
</component>
</class>
</hibernate-mapping>