I have the following Java objects, truncated to emphasize the necessary details.
Code:
public class SurveyQuestion {
private int questionNumber;
}
public class SurveyResponse {
// appropriate getter exists and is mapped to the SurveyQuestion class
private SurveyQuestion question;
int responseOrder;
SurveyHeader header;
@ManyToOne()
@JoinColumn(name="ResponseID", nullable=false)
public SurveyHeader getHeader () {
return header;
}
}
public class SurveyHeader {
@OneToMany(mappedBy="header", orphanRemoval=true)
@Cascade(value={CascadeType.ALL})
@OrderBy("question.questionNumber, responseOrder")
public List<SurveyResponse> getResponses () {
return responses;
}
}
The problem comes with the @OrderBy annotation. If I try this, I get the error message:
property from @OrderBy clause not found: edu.hope.cs.surveys.dao.pojo.SurveyResponse.question.questionNumber
Note that SurveyResponse does have a property named question, and that object does have a property named questionNumber.
If I change the @OrderBy to:
Code:
@OrderBy("question, responseOrder")
then the code runs, but the order by clause generated by Hibernate uses the primary key of the SurveyQuestion object as the column, not the one that I want it to use (questionNumber).
What am I doing incorrectly?
Thanks!
Ryan