-->
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: Help using @OrderBy annotation
PostPosted: Fri May 13, 2011 4:52 pm 
Newbie

Joined: Mon Jul 20, 2009 7:11 am
Posts: 6
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


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.