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]