P
P
P_Alexander2018-03-26 20:21:08
PostgreSQL
P_Alexander, 2018-03-26 20:21:08

How to write a Criteria hibernate join query?

Help me make a CRITERIA request, or send a tutorial explaining how to do it, or explain to me with this example what is substituted where!...
Where the relation of userentity to statgame is one to many.
The SQL query is "SELECT * FROM testproj.userentity u JOIN testproj.statgame s ON u.id=s.userid WHERE u.id= :id" <- this should be dynamically populated as needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yerlan Ibraev, 2018-03-27
@P_Alexander

What for?!
You will have a simple select like
A statgame pull through @OneToMany
Simple select in CriteriaAPI

...
 CriteriaBuilder cb = em.getCriteriaBuilder();

  CriteriaQuery<userentity > q = cb.createQuery(userentity .class);
  Root<userentity > c = q.from(userentity .class);
  ParameterExpression<Integer> p = cb.parameter(Integer.class);
  q.select(c).where(cb.gt(c.get("id"), p));
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question