Questions tagged [criteriaquery]

245 questions
5
votes
4 answers

JPA CriteriaQuery compare Timestamp ignore time portion

Let say I have a column in Oracle DB like this: SOMETHING_TS TIMESTAMP WITH TIME ZONE And I would like to use CriteriaQuery to filter by this column. I can used native query to achieve this: SELECT * FROM SOMETHING WHERE…
Javatar
  • 623
  • 3
  • 8
  • 20
5
votes
0 answers

Convert Hibernate Criteria to JPA CriteriaQuery

I'm looking for a solution to "easily" convert Hibernate Criteria code to JPA Criteria Query code without re-writing all the stuff one-to-one. Is it possible to convert the Hibernate Criteria to an SQL query and then reuse it with the JPA Criteria…
Bibs0u67
  • 106
  • 5
4
votes
1 answer

JPA Criteria API join query One To Many with condition

I have 2 Table Enterprise ID Name 1 Alex Product ID Name Status EnterpriseId 7 Iphone12 ACTIVE 1 8 Iphone11 ACTIVE 1 6 Iphone13 DISABLE 1 The relationship is one to many (one Enterprise having many Product). I want to…
4
votes
1 answer

Why does this Hibernate Criteria Query fails with "No explicit selection and an implicit one cold not be determined"?

I have an entity called Bucket, and I'm trying to build a criteria query to determine whether there is a Bucket stored with the "Name" property equals to "Bucket_1". So basically it is an exists query. There is nothing special about the Bucket…
Edy Bourne
  • 5,679
  • 13
  • 53
  • 101
4
votes
4 answers

ORDER BY in Criteria API for a computed column name (by alias)

Having a situation where my java code is symbolic to query - SELECT CUSTOMER_ID, CUSTOMER_NAME, CASE WHEN COUNT (DISTINCT CARD_ID) > 1 THEN 'MULTIPLE' ELSE MAX(CARD_NUM) END AS CARD_NUM …
user3499836
  • 87
  • 1
  • 9
4
votes
1 answer

Get row from entity on hibernate with count and join

I'm trying to get a field name from one table that has a join using hibernate. Does someone know how to get it? I'm using spring boot with EntityManager. The query is: "SELECT COUNT(post_id), t.name" + " FROM TagsPosts tp" + " JOIN Tags t" + " WHERE…
Al Elizalde
  • 337
  • 1
  • 3
  • 12
4
votes
0 answers

jpa2 CriteriaBuilder order by "ORDER BY expressions must appear in select list"

I'm writing a query with CriteriaBuilder, but it has not been possible to add the order by clause, because an error it's thrown with the message ORDER BY expressions must appear in select list this are my entities. public class A{ Integer aId; …
OJVM
  • 1,403
  • 1
  • 25
  • 37
4
votes
2 answers

How do I write a JPA criteria query that matches a collection exactly?

I’m using JPA 2.0 with Hibernate 4.1.0.Final. I have a couple of classes, Groups and GroupMembers. Each GroupMember is tied to a user object @Entity @Table(name = "group") public class Group { @Id @NotNull @GeneratedValue(generator…
Dave
  • 15,639
  • 133
  • 442
  • 830
3
votes
1 answer

building a criteria query with jpa 2.0 by using a dynamic list

I'm a bit confused while creating a criteriaQuery with JPA 2.0. Prerequisites: I have a Gui, where the user can mark some checkboxes of (let us say) wheatherstations with some options like temperature/wind/timeperiod/etc... Now I want to set up a…
RonH
  • 140
  • 2
  • 14
3
votes
1 answer

Order result set based on the size of collection in an entity

Consider the entities below - class Team { private String name; @OneToMany private Set employees; } class Employee { private String name; @OneToMany private Set skills; } class Skill { private String…
Tapan
  • 157
  • 2
  • 4
  • 18
3
votes
1 answer

JPA CriteriaBuilder with CONCAT_WS function throws NullPointerException

I have the following CriteriaQuery that I use to filter orders. CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(OrderReducedDTO.class); Root root = cq.from(Order.class); Join
MorganGlam
  • 129
  • 2
  • 11
3
votes
0 answers

Spring - Pageable with Distinct and order by using another table's field

I have a custom repository and this is the method that I used to find Transporters based on a certain filter, sorted by whatever column is picked (Either organization number, transporter, address line 1, postal code, and postal name) @Override …
3
votes
1 answer

Create a Predicate to match an entity with an entry in a Map property

I'm trying to create a javax.persistence.criteria.Predicate to match entities which contain a certain key/value entry in a Map property. This is in the context of Spring Data JPA and a JpaSpecificationExecutor
ptomli
  • 11,730
  • 4
  • 40
  • 68
3
votes
0 answers

JPA Query where statement on the selected fields result

With Criteria Builder / Criteria Query is it possible to use the selected fields in the where statement? My end goal is to be able to let the UI apply filters to the DTO and I'm thinking the easiest way would be to be apply those filters on the…
John
  • 1,808
  • 7
  • 28
  • 57
3
votes
1 answer

How can I do a subquery in a JPA Criteria Builder Select statment?

I'm trying to do a select statement using CritierBuilder/CrtieriaQuery to select certain fields from table A and then a boolean flag if that record exists in another table. Basically, I have a list of "officers", and a list of users. Users are…
John
  • 1,808
  • 7
  • 28
  • 57
1
2
3
16 17