I'm unable to access the values in an Embedded Class.
Criteria cr = this.getHibernateTemplate().getSessionFactory().openSession().createCriteria(DuaVO.class,"Dua");
if (duaSearchVO.getContractNum()!=null && !duaSearchVO.getContractNum().isEmpty()) {
cr.createCriteria("Dua.contractFundingDetails", "contractFundingDetails");
cr.add(Restrictions.eq("contractFundingDetails.contractNumber", duaSearchVO.getContractNum()));
flag = true;
}
Junit Test
@Test
public void testsearchDua() {
DuaSearchVO duaSearchVO = new DuaSearchVO();
//ContractFundingDetailsVO - contractNumber
duaSearchVO.setContractNum("HHS12132423");
List<Object[]> result = duaSearchDaoImpl.searchDua(duaSearchVO);
Assert.assertNotNull(result);
}
I get this exception.
org.hibernate.QueryException: Criteria objects cannot be created directly on components. Create a criteria on owning entity and use a dotted property to access component property: contractFundingDetails
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:274)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:230)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:112)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:86)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1568)
Main Class (DuaVO)
@Embedded
private ContractFundingDetailsVO contractFundingDetails;
Embedded Class
@Embeddable
public class ContractFundingDetailsVO implements Serializable
{
@Column(name="CNTRCT_NUM")
private String contractNumber;
}
Solved.
I don't have to create a createCriteria() method since there are no joins.