Ok, so I'm still somewhat of a newbie to Java and hibernate and I'm trying to search for a question/answer set in my database, and I can pull up the set just fine if I type in the exact question, but when I use the like operator nothing works, and I'm really not sure what to do. I'm only searching for the question, and it's part of the same object as the answer, so I just pull up the answer with it as well.
Here's my code in my QuestionAnswerDao
public QuestionAnswerSet getQuestionAnswerSetByQuestion(String question)
{
Session session = (Session) em.getDelegate();
return (QuestionAnswerSet) session.createCriteria(QuestionAnswerSet.class).add(Restrictions.eq("question", "%"+question+"%")).uniqueResult();
}
Also here's my code in my controller
@RequestMapping(value="search", method=RequestMethod.GET)
public String searchGet (ModelMap model, HttpServletRequest request)
{
SearchForm searchForm = new SearchForm();
model.put("searchForm", searchForm);
return "app/search";
}
@RequestMapping(value="search", method=RequestMethod.POST)
public String searchPost (@ModelAttribute("searchForm") SearchForm searchForm, ModelMap model, HttpServletRequest request)
{
QuestionAnswerSet questionAnswerSetByQuestion = questionAnswerDao.getQuestionAnswerSetByQuestion(searchForm.getSearchString());
model.put("searchResult", questionAnswerSetByQuestion);
return "app/search";
}
If anyone could help me out with this that would be great, thanks.
${searchResult.answer}
${searchResult.question}