Database: postgres 8.x
Ebean: 2.6.1
I have 3 class, "Question", "Tag", "QuestionTagR".
Question and Tag are ManyToMany, but they are not using "ManyToMany"
directly, instead, using many "OneToMany" through "QuestionTagR"
@Entity
public class Question {
@OneToMany
public List<QuestionTagR> tagsR;
}
@Entity
public class Tag {
@OneToMany
public List<QuestionTagR> questionsR;
@Column
public int quesitonCount;
}
@Entity
public class QuestionTagR {
@ManyToOne
public Question question;
@ManyToOne
public Tag tag;
}
Now I want to query all the tags of a question, so I write the code:
Question question = getQuestion();
Ebean.query(Tag.class).where().eq("questionsR.question",
question).orderBy("questionCount desc").findList();
But there is an error reported:
PersistenceException occured :
Query threw SQLException:
ERROR:
for SELECT DISTINCT, ORDER BY expressions must appear in select list
Query was:
select distinct
t.id as c0,
t.name as c1 from tags t join
questions_tags_r xq on xq.tag_id =
t.id where xq.question_id = ? order
by t.question_count desc
I don't understand why there is a "distinct" in the query. If there is
no "distinct", or no "order by", then everything is OK.
I don't know how to fix this. I have spent 2 hours on debuging, but
not find the reason.