1

I have a problem with Join in Criteria API - I need to execute this SQL: SELECT eventConf.DEPT_ID FROM EVENT_CONF eventConf JOIN EVENT event ON event.EVENT_CONF_ID = eventConf.ID JOIN TASK task ON task.EVENT_ID = event.ID;

Problem is, that when try to "translate" this into Criteria API classes, like this:

Subquery<Long> subquery3 = cq.subquery(Long.class); Root<EventConf> subquery3Root = subquery3.from(EventConf.class); Join<EventConf, Event> eventJoin = subquery3Root.join(Event_.eventConf); 

My IDE shows me, that

Cannot resolve method 'join(javax.persistence.metamodel.SingularAttribute<atc.edpo.source.entity.Event,atc.edpo.source.entity.EventConf>) 

It is understandable, because Event_.evenConf is type of SingularAttribute< Event, EventConf > and Root parameterized as EventConf, but how do you make a Join, when target entity contains id of source entity? Or can I make some kind of analog of Join in this situation?

1 Answer 1

1
*You can use FetchMode Criteria critiera = sessionFactory.getCurrentSession().createCriteria(EventConf.class); critiera.setFetchMode("event", FetchMode.JOIN) .setFetchMode("task", FetchMode.JOIN) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); critiera.list();* 
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, but this won't help, because i need to use CriteriaQuery(like main query, thats why I am using Subquery in the example, because all I need, it's just make Predicate for the main query, like DEPT_ID from what I selected is equal to user's DEPT_ID) and CriteriaBuilder. So the main question - is the there any way to make join when target entity contains reference to source with these classes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.