问题
I have simple query with two joins:
SELECT p.id, BU.ID, BU.TEXTLANG as Title FROM PROJEKT P
JOIN Text BT ON BT.ID = P.TITEL_ID
JOIN Uebersetzung BU ON BU.TEXT_ID = BT.ID
WHERE BU.TEXTLANG LIKE '%Spatial%';
This query must be converted to a typesafe query, what i tried is:
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Projekt> query = criteriaBuilder.createQuery(Projekt.class);
final Root<Projekt> projekt = query.from(Projekt.class);
Join<Projekt, Text> bt = projekt.join(Projekt_.titel);
Join<Text, Uebersetzung> bu = bt.join(Text_.uebersetzungen);
Predicate condition = criteriaBuilder.like(bu.get(Uebersetzung_.textLang),"%Spatial%");
query.where(condition);
query.distinct(true);
query.orderBy(criteriaBuilder.asc(projekt.get(Projekt_.id)));
My problem is, that i want to get the field Uebersetzung_.textLang as selection. But when i try to add selection to the query, for example:
query.multiselect(bu.get(Uebersetzung_.textLang));
i get an error message:
org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null".
I need this field, because i want to access it from the jsp page. Is there any other way to get this field in the selection?
来源:https://stackoverflow.com/questions/6660819/set-selection-of-typesafe-jpa-2-query-with-joins