Suddenly I need to concat my sHQL instead of using setParameter??
Hello guys!I ran into something strange yesterday that I have not solved in a pleasant way.
Some code that used to work stopped working.
As you see below I have comment-away the lines that used to work, and replacet it with one ugly concat row.
Then it worked, but of course I can not understand way and I do not like it.
public Payment getPaymentForReferens(final String referens) throws PaymentNotFoundException
{
//final Query tPaymentQuery = em.createQuery("SELECT b FROM Payment b WHERE b.referens = :referens");
//tPaymentQuery.setParameter("referens", referens);
final Query tPaymentQuery = em.createQuery("SELECT b FROM Payment b WHERE b.referens = " + referens);
Payment payment = null;
final List<?> results = tPaymentQuery.getResultList();
if(!results.isEmpty()) {
payment = (Payment)results.get(0);
}
if(payment == null) {
throw new PaymentNotFoundException(PaymentNotFoundException.PAYMENT_WITH_THIS_REFERENS_CAN_NOT_BE_FOUND + referens);
}
return payment;
}
All suggestions, comments and ideas what might have gone wrong is most welcome!
The field/column in the database for 'referens' is char(36) in a Oracle.
Best regards
Fredrik
