Questions tagged [jpa-criteria]

A type-safe, portable API for defining queries for entities - similar to JPQL

Docs

117 questions
1
vote
1 answer

Alternate way for the code using JPA criteria

With deprecation of createCriteria() in Criteria class in Hibernate 5.2.2, many of its related functions can't be used anymore. I have found an alternative use for criteria.createAlias(String, String) and adding Restriction from the following…
Nashreen
  • 21
  • 4
1
vote
1 answer

Explain the meaning of JPA Criteria API From class and its type parameters

What is the purpose of class javax.persistence.criteria.From and what do its type parameters Z and X stand for ? The documentation is not clear at all. I became even more confused after I saw that the type javax.persistence.criteria.Root has the…
Suren Aznauryan
  • 984
  • 10
  • 24
1
vote
1 answer

Bulk insert with JPA criteria builder

I currently a spring boot project with postgres and hibernate and had the following functions: private fun savePost(post: Post): Post = entityManager.merge(post) private fun savePosts(posts: List) = posts.forEach { save(post) } I…
Jon Doe
  • 23
  • 5
1
vote
0 answers

JPA CriteriaBuilder - alternative wildcard characters

In a query like this predicates.add(cb.like(fromPet.get(Pet_.name), name)); It accepts "%" as a replacement for any amount of characters and "_" as a replacement for any single character. is it possible to redefine these two wildcards-characters,…
1
vote
0 answers

Hibernate - JPA - oneToMany - count as subquery and use as a Predicate

I have the following relation and I need to get consumers which have at least one purchase (as a subquery, because this is a part of a bigger query). @Entity @Table(name = "consumers") public class Consumer extends User { @JsonIgnore …
1
vote
1 answer

Query in Spring JPA using List of two parameters

public interface InventoryRepository extends JPARepository { List findByIdIn(List ids); } Above is working fine, however in same way I am trying to fetch the List or Map, based on multiple params List ids and…
1
vote
1 answer

JPA Criteria Expression Replace Character

In type String to replace all - with * I can write String firstName = firstName.replaceAll("-", "*"); Is there a way to do the same in Criteria Expression? I need to remove special characters from the first name before comparing it to the pattern…
Jumana Alhaddad
  • 285
  • 2
  • 6
  • 17
1
vote
1 answer

Join and inheritance jpa

I use spring data, jpa with hibernate implementation I am writing a advanced search public class Samples extends BaseEntity{ .. @Id @ManyToOne @JoinColumns({ @JoinColumn(name = "sampling_id", referencedColumnName = "id"), …
robert trudel
  • 5,283
  • 17
  • 72
  • 124
1
vote
1 answer

Difference Between toPredicate() Method and And/Or/Not/Where in JPA Criteria API Specification<>

I am now exploring the JPA Criteria API for creating the dynamic queries and type safe queries. I am exploring how to use Specification. When I am exploring I found that toPredicate() method using to create where clause for the query referenced by…
Mr.DevEng
  • 2,651
  • 14
  • 57
  • 115
1
vote
1 answer

Entity JOIN using Spring Data Specification

I'm currently messing around with Spring Data JPA Specifications. I came across the following question: How can I define the following SQL Join with just JPA Specifications? SELECT * FROM competition c LEFT JOIN participation p ON c.id =…
1
vote
1 answer

Hibernate using Criteria API sends too many queries to database

I was under the impression that by doing fetching hibernate would reduce the number of queries but obviously this is not the case. This is my root class: public class Ereturn { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) …
masber
  • 2,875
  • 7
  • 29
  • 49
1
vote
0 answers

Cast a numeric field to a varchar of a specific length

I have a numeric id field in an entity that I want to concatenate to some other string. Right now I'm doing: cb.concat( from.get("id").as(String.class) , otherString ) That works and it is translated to CAST(mytable.id AS VARCHAR(255). I want…
gmc
  • 3,910
  • 2
  • 31
  • 44
1
vote
1 answer

Spring JPA Criteria with Repository, ManyToOne, Select on field of joined table

I'm trying to create a JPA predicate to use as an argument in my JPA repository in order to return results based on a field in the joined table. It never actually filters anything. I get all objects of the primary table back. JPA criteria seems like…
Rig
  • 1,276
  • 3
  • 22
  • 43
1
vote
1 answer

Query creation using dynamic filter map in QueryDSL and spring data JPA

I am using Spring Data and JPA in my application and I am trying to implement QueryDSL for dynamic criteria API. As far as if I send specific values in criteria, it works fine using below predicate: Predicate predicate =…
yateen
  • 85
  • 1
  • 7
1
vote
2 answers

How to get distinct values of a single column in Criteria API(JPA)

Hi I am new for JPA & Criteria API. I am trying to fetch distinct values of a single column (trying to get only distinct values of TestId).I have below table in my DB. __________________________________ |TestId(Pk) | TestCol(PK) |…
PKS
  • 129
  • 10