public String findTextByQueryReplyAndQueryField ( QueryReply queryReply , QueryField queryField ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < String > criteria = criteriaBuilder . createQuery ( String . class ) ; Root < QueryQuestionOptionAnswer > root = criteria . from ( QueryQuestionOptionAnswer . class ) ; Join < QueryQuestionOptionAnswer , QueryOptionFieldOption > option = root . join ( QueryQuestionOptionAnswer_ . option ) ; criteria . select ( option . get ( QueryOptionFieldOption_ . text ) ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( root . get ( QueryQuestionOptionAnswer_ . queryField ) , queryField ) , criteriaBuilder . equal ( root . get ( QueryQuestionOptionAnswer_ . queryReply ) , queryReply ) ) ) ; return getSingleResult ( entityManager . createQuery ( criteria ) ) ; }
Finds answer text by query reply and query field