I can not understand how to make a comparison in hibernate cruteria. There is such a method

@Override public List<PollEvent> getPollForUpdate(IncomingSms incommingSMS) { Criteria criteria = getSession().createCriteria(PollEvent.class); criteria.add(Restrictions.eq("status", 0)); criteria.add(Restrictions.eq("call.callingnum", incommingSMS.getSourceAddress())); return criteria.list(); } 

It must return a list of objects. But he turns a mistake. swears on criteria.add(Restrictions.eq("call.callingnum", incommingSMS.getSourceAddress()));

In the PollEvent class, PollEvent is a call field here

 @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "CALL_ID", nullable = false) private Calls call; 

And he has a field callingnum on which I want to compare

 @Column(name = "CALLINGNUM", length = 15) private String callingnum; 

The error that I get

 could not resolve property: call.callingnum of: polls.entety.PollEvent 

    1 answer 1

    In this case, you need to create either nested criteria :

     Criteria criteria = getSession().createCriteria(PollEvent.class); criteria.add(Restrictions.eq("status", 0)); criteria.createCriteria("call") .add(Restrictions.eq("callingnum", incommingSMS.getSourceAddress())); 

    or use alias :

     Criteria criteria = getSession().createCriteria(PollEvent.class); criteria.add(Restrictions.eq("status", 0)); criteria.createAlias("call", "c"); criteria.add(Restrictions.eq("c.callingnum", incommingSMS.getSourceAddress())); 

    Documentation

    • Found a solution earlier but the answer is correct. thank! - user5620472