Hello all,
I'm new to Hibernate, Java developer for 7+ years. I've got two Hibernate books that I have reviewed and started working with. I am writing code that is trying to do the following:
Open a transaction Create criteria with restrictions Order by... BUT the order by that I need to order by is VoterHistory.election.electionDate's date In the class VoterHistory, I have the following: { long id; Voter voter; Election election; VoteMethod voteMethod; }
Code Snippet: Transaction tx = session.beginTransaction(); try { Voter voter = (Voter) session.get(Voter.class, voterId); if(voter == null){ throw new DAOException("Invalid Voter ID: " + voterId); }
Criteria criteria = session.createCriteria(VoterHistory.class); criteria.add(Restrictions.eq("voter", voter)); // correct?? criteria.addOrder(Order.desc("election.electionDate"));
if(voterHistoryExample != null){ Example example = Example.create(voterHistoryExample); example.enableLike(); criteria.add(example); }
List<VoterHistory> voterHistories = criteria.list();
************ Question How can I access the VoterHistory.election.electionDate in order to sort by date? Do I need to change or add information to the .hbm.xml mapping file?
Thanks Phil
|