Below piece of code is supposed to return list of entities for which the primarykeys(idList) match in DB.
This works fine for primitive Id types, but for composite keys, it does not. please help me.
Class<?> entityType = TypeToken.of(typeOfEntity).getRawType();
Class<?> idType = TypeToken.of(typeOfId).getRawType();
String idFieldName = getIdFieldName(entityManager, entityType, idType);
CriteriaQuery<?> criteria = entityManager.getCriteriaBuilder().createQuery(entityType);
Root<?> root = criteria.from(entityType);
Expression<ID> expression = root.get(idFieldName);
Predicate predicate = expression.in(idList);
TypedQuery<?> query = entityManager.createQuery(criteria.where(predicate));
return (List<T>) query.getResultList();
I am using Hibernate now, and when i run the test i got the following sql from hibernate logs.
select * from paper_invoice paperinvoi0_ where paperinvoi0_.paymentid=? and paperinvoi0_.receipt_code=? and paperinvoi0_.usetype=?
This looks fine, but it throws an exception: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query.
I am not sure whats the issue here. can anyone point out ?