-->
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.  [ 1 post ] 
Author Message
 Post subject: Set and Order
PostPosted: Tue Apr 12, 2005 12:36 am 
Newbie

Joined: Mon Apr 11, 2005 11:14 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.6

I have three tables as the following:

create table book (
id bigint not null,
title varchar(255) not null,
publish_date date,
primary key(id)
);

create table book_author(
book_id bigint not null,
author_id bigint not null
);

create table author(
id bigint not null,
name varchar(63) not null
);

Thes mapping file as the following:

<hibernate-mapping>

<class name="Book" table="book">

<id name="id" column="id">
<generator class="native"/>
</id>

<property name="title"/>
<property name="publish_date"/>

<set name="authors" table="book_author" lazy="true">
<key>
<column name="book_id" not-null="true"/>
</key>
<many-to-many class="Author">
<column name="author_id" not-null="true"/>
</many-to-many>
</set>
</class>

<class name="Author" table="authors">
<id name="id" column="id">
<generator class="native"/>
</id>

<property name="name"/>

<set name="books" table="book_author" lazy="true">
<key column="author_id"/>
<many-to-many class="Book" column="book_id"/>
</set>

</class>
</hibernate-mapping>

I want to use the following statement to query the author's information
and the book wroten by him at the same timeļ¼š

session.createCriteria(Author.class).add(Expression.eq("id", id))
.uniqueResult();


But how can I order the book set by the "publish_date" column?

When I am using this:

<set name="books" table="book_author" lazy="true" order-by="publish_date asc">
<key column="author_id"/>
<many-to-many class="Book" column="book_id"/>
</set>

there will be an error.

What should I do?

Thanks.[/b]

_________________
Hello, World!


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

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.