I have the following 3 tables:
Code:
CREATE TABLE test (
testID INTEGER(10) NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NULL,
description TEXT NULL,
PRIMARY KEY(testID)
);
CREATE TABLE questions (
questionID INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
question TEXT NULL,
PRIMARY KEY(questionID)
);
CREATE TABLE test_Question (
testID INTEGER(10) UNSIGNED NOT NULL,
questionID INTEGER(10) NOT NULL,
order INTEGER(3) NULL DEFAULT '0',
PRIMARY KEY(testID, questionID)
);
I have the following mapping:
Code:
<class name="pack.Testclass" table="test" >
<id name="testID" column="testID" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="name" column="navn" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<set name="questions" table="test_Question">
<key column="testID" />
<many-to-many column="questionID" class="pack.Question" />
</set>
</class>
How can I use the order field in the association table to order the results?
I can easily retrieve a Test and it's associated questions but I can't figure out how to order the questions using a column from the test_Question table.
I'm using the following code to retrieve a Test object:
Code:
session.load(pack.Test.class, new Integer(1));