Questions tagged [criteriaquery]

245 questions
2
votes
1 answer

How to implement this SQL using CriteriaBuilder to build a Predicate?

Im using Specifications that use CriteriaBuilder to filter data which is called from my JpaRepository using findAll(), but now I have a more complicated query in SQL that I need to generate a Predicate in my specification. The SQL query is: SELECT…
Eno
  • 10,730
  • 18
  • 53
  • 86
2
votes
1 answer

Criteria API Specification - Filter records and return only the latest record for many to one mappings

I have two tables, Lead and LeadActivity. A lead can have many lead activities and mapping is done as @ManyToOne form LeadActivity to Lead. Problem Statement -I want to to filter LeadActivity records such that, If there are more than one…
2
votes
1 answer

JPA 2, join criteria query without entity mapping

I have the following tables: customers orders @Entity public class Customer { String id; } @Entity public class Order { String id; String customerId; } I have no use to establish an entity's mapping between…
Fabrizio Stellato
  • 1,727
  • 21
  • 52
2
votes
1 answer

Hibernate only error: "Column must appear in the GROUP BY clause or be used in an aggregate function"

I have this query generated by hibernate (printed on console) and it works fine if directly executed throwg pgAdmin4: select my_entity0_.status as col_0_0_, calc_sub_status( my_entity0_.status, …
smaudi
  • 83
  • 7
2
votes
1 answer

How to rewrite this query using JPA Criteria Query?

public class Entity { private boolean suspended; private String code; @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @DateTimeFormat(style = "S-") private DateTime validFrom; @Type(type =…
Vlada
  • 559
  • 2
  • 11
  • 27
2
votes
4 answers

JPA/Hibernate typesafe DELETE queries

The only CriteriaQuery examples I've seen are for SELECT queries. Is there a way to construct typesafe DELETE queries, either with JPA 2 or Hibernate APIs?
hertzsprung
  • 9,445
  • 4
  • 42
  • 77
2
votes
1 answer

How to discover Implicit multiple root

here's my show case code: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery q = cb.createTupleQuery(); Root aa =…
lelmarir
  • 593
  • 2
  • 7
  • 24
2
votes
2 answers

Hibernate Criteria, createAlias() If Alias is Null

In the code below.. There are two Alias as Entity Object Reference. Sometimes "caseStage" as stage can be null in Database. When "caseStage" is null I want stage.name value as an empty String or something customized like "---"…
Mr. Mak
  • 837
  • 1
  • 11
  • 25
2
votes
0 answers

Is there a standard way of sending dynamic search parameters for a SQL query, from a client side (HTML form)?

I want to understand how I can write dynamic SQL calls, which can be used to retrieve rows, based on an end user's search criteria. I am in particular wondering about how to structure the data sent from the client side to the server. I'm going to…
2
votes
0 answers

JPA TypedQuery getResultList() performance is very slow

My code looks like: final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); final TypedQuery createQuery = criteriaBuilder.createQuery(ObjectTO.class); ... // Logic to create search query ... // On this line performance…
user613114
  • 2,731
  • 11
  • 47
  • 73
2
votes
1 answer

JPA: Find all articles that have a common set of tags

I have the following entities: @Entity public class Article{ @Id private String id; @ManyToMany(cascade = CascadeType.PERSIST) private Set tags; //non-relevant code } @Entity public class Tag{ @Id private String…
Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82
2
votes
1 answer

Complex criteria query: using JPA instead of NativeQuery

I've in my Java EE project this NativeQuery for MySQL: SELECT *, ROUND((price_2-price_1)*100/price_1,2) AS varprice_1, ROUND((quantity_2-quantity_1)*100/quantity_1,2) AS varcant_1, ROUND((price_3-price_2)*100/price_2,2) AS…
moretti.fabio
  • 1,128
  • 13
  • 32
2
votes
1 answer

How to get an interesect query using CritieraQuery?

Given @Entity public class Document { @Id @Column(name = "DOCUMENT_ID") private Long id; @ElementCollection @CollectionTable( name="TAG", joinColumns=@JoinColumn(name="DOCUMENT_ID") ) …
Tomasz
  • 5,269
  • 8
  • 56
  • 65
2
votes
1 answer

CriteriaBuilder and isMember of list on entity (Hibernate)

Okay, I'm trying to do something quite strange. I'm trying to use CriteriaBuilder and CriteriaQuery to return all entities who contain a given object in a collection on the entity. I've been banging my head against this for hours and the relevant…
Apropos
  • 508
  • 5
  • 15
1
vote
1 answer

JPA Join criteria query with singular attribute

I have 2 entities like these: EntityX: id Long name String entityYId Long EntityY (this entity is very hard, because it has a lot of data) id Long name String xxx xxx ..... I need to do something like Root xRoot =…
user1228739
  • 153
  • 3
  • 19