Skip to content
Advertisement

Tag: criteria

How do I cast JPA criteria Expression to long java type

This code has not compile error but at run time gets this error: Cannot cast from Expression to int I tried using String: This also gets error: ERROR: For input string: “org.hibernate.query.criteria.internal.path.SingularAttributePath@2ed2d35d”; nested exception is java.lang.NumberFormatException: For input string: “org.hibernate.query.criteria.internal.path.SingularAttributePath@2ed2d35d” Answer In your first error, you are mixing LocalDateTime.now().minusDays with the Expression root.get(“person”).get(“birthDay”).as(Long.class), and it is not possible. The error

Criteria API how to write = ANY(?1) expression?

I have a query that I want to translate to Criteria API. A query After java processes it (native sql query) the final query looks like this My Question is how to translate = ANY(?1) part to Criteria API? I see that any() definition is How to put array of values to it? I’m using PostgreSQL Answer You will need

How can I build a predicate filtering to where ALL tags in an array exist, joined to a record, using criteriaBuilder?

Here’s an example of the syntax I’m using for another condition (where ANY of the tags appear on the document via a FK). predicates.add(root.join(Document_.tags).in({ pseudocode array of tags })); I’m trying to come up with a similar predicate, but where the Document entity has ALL of the tags listed in the filter. Answer if all the tags listed in the

Spring Data Mongodb Query by embedded document id

i am trying to query a model that contains a @Reference as attribute like: and so on, then i have a query with more logic and code but in resume i have to filter by the field _id from Branch object, its just id on the object but on database its _id, ok no problem its normal behavior for the

Spring Boot Jpa specification Set Enums IN Set Enums

Hi I want filter restaurant by type using Specification, but I get error: Parameter value [SUSHI] did not match expected type [java.util.Set (n/a)] How Can I comare List enums to list enums ? :/ My specification file: Restaurant model: Restaurant category: Answer Had the same problem and this question helped me. In my case, I wanted to search my commissions

How to paginate a JPA Query

I have a submission table with columns like ID, Name, Code among other properties. My requirement is to search for records based on the mentioned properties and return a paginated set. This is the pseudocode for what I am looking for: There seem to be many options like CriteriaBuilder, NamedQuery, etc. Which is the most efficient one in this situation?

Advertisement