-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Order results based on column in association table
PostPosted: Tue Apr 20, 2004 7:31 am 
Newbie

Joined: Tue Apr 06, 2004 6:37 am
Posts: 17
Location: Oslo, Norway
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));


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 9:08 am 
Newbie

Joined: Tue Apr 06, 2004 6:37 am
Posts: 17
Location: Oslo, Norway
I read this FAQ and guess this is the way to do it, but I still can't get it to work. Does anyone have a better example?

http://www.hibernate.org/118.html#A10


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.