criteria-api

How to join multiple columns using Specification in JPA?

左心房为你撑大大i 提交于 2019-12-11 16:24:29
问题 I'm trying to convert a query into a JPA Specification, the query contains JOIN operation with OR condition. Here is the Query : select u from User u inner join Operation o on (u.id = o.verificateur1 or u.id = o.verificateur2) where o.id not in (:ids) I tried to write a specification but I'm blocked on how to join multiple column with OR condition. public class UserSpecification { public static Specification<User> UsersNotInSelectedOperations(final List<Long> operationId ){ return new

Load collections eagerly in NHibernate using Criteria API

会有一股神秘感。 提交于 2019-12-11 16:06:08
问题 I have an entity A which HasMany entities B and entities C. All entities A, B and C have some references x,y and z which should be loaded eagerly. I want to read from the database all entities A, and load the collections of B and C eagerly using criteria API. So far, I am able to fetch the references in 'A' eagerly. But when the collections are loaded, the references within them are lazily loaded. Here is how I do it AllEntities_A = _session.CreateCriteria(typeof(A)) .SetFetchMode("x",

jpa criteria query, match any of list passed as parameter

有些话、适合烂在心里 提交于 2019-12-11 15:51:58
问题 I'm trying to write a DAO method where I select any number of Widgets that have a matching tag. So in entities like: @Entity public class Widget { @Id private id; @OneToMany (cascade = CascadeType.ALL) private List<Tag> tagList; } @Entity public class Tag { @Id private int id; String tagValue; } and in my DAO, I'm trying to write a method that will take in a list of strings List<String> myList = new ArrayList<String>(); myList.add("tom"); myList.add("dick"); myList.add("harry"); to the DAO

JPA 2 Criteria API - Exception converting JPQL to Criteria API query with Eclipselink

筅森魡賤 提交于 2019-12-11 15:02:47
问题 I'm having trouble converting a JPA query to the use the Criteria API I have the following query that attempts to find a ServiceUser matching a passed address parameter. ServiceUser is an abstract entity with concrete subclasses Child and Adult. I'm using the joined inheritance strategy on the ServiceUser class. Everything works fine when I call this method. public Set<T> findByAddress(Address address) { Query query = manager.createQuery("SELECT distinct s FROM ServiceUser AS s JOIN s

JPA 2 Criteria API using metamodel case sensitive condition

旧时模样 提交于 2019-12-11 08:17:02
问题 I have the following line of code to get the results based on like statement using Hibernate 4 API Predicate predicate = cb.like(emp.get(EmployeeDetail_.empName), empName+"%"); The generated sql statement is select employeede0_.EMPLOYEE_NAME as EMPLOYEE1_0_ from EMPLOYEES employeede0_ where employeede0_.EMPLOYEE_NAME like 'smith%' How can I modify my java code to have EMPLOYEE_NAME in lower case? The generated sql output should be like the following select employeede0_.EMPLOYEE_NAME as

How to use SUM aggregate in JPA Specification?

吃可爱长大的小学妹 提交于 2019-12-11 07:44:44
问题 I am trying to write a specification in order to restrict returned values of findAll() repository method. I can add groupBy and orderBy clause but cannot use sum aggregate (no errors but can't see aggregate result SUM_TOTAL in logged query). here is my code: public static Specification<Commande> searchCommandWith(final Long dId, final Long gId, final Long pId, final LocalDate date1, final LocalDate date2) { return new Specification<Commande>() { @Override public Predicate toPredicate(Root

month() function and year() function in postgresql through jpa2

这一生的挚爱 提交于 2019-12-11 07:01:58
问题 How to get the month and year of a postgresql date field using jpa2 criteria query or jpql? Has anybody done this? 回答1: Use this: FUNC('MyFunc', a, b, c) Example: SELECT FUNC('to_char', current_date, 'month') 回答2: A few examples, how to extract the month from a date or timestamp in PostgreSQL: select to_char(now(), 'month'); select to_char(now(), 'MM'); select extract('month' from now()); select date_part('month', now()); Just read the manual. 回答3: With JPA criteria API (tested only with

Basic date/time manipulation in NHiberate query

≡放荡痞女 提交于 2019-12-11 06:56:27
问题 I'm trying to restrict my NHibernate query with some basic date/time manipulation . More specifically, I want to execute the following statement (pseudo-SQL): select * from article where created_on + lifespan >= sysdate with: created_on is mapped to a property of type DateTime . lifespan is mapped to a property of type TimeSpan . sysdate is the current date/time (of the database server or ofthe application host, I don't care) Is there any built-in way to do that by using the Criteria-API or

How can I add a criteria to a grails criteria to limit results based on a filtered association?

家住魔仙堡 提交于 2019-12-11 06:33:31
问题 In my old java code I could do this to "join" another table in a hibernate query and filter results based on it. final Criteria brokerageCriteria = userCriteria.createCriteria("brokerage"); if (queryDto.getBrokerageID() != null) { brokerageCriteria.add(Restrictions.eq("id", queryDto.getBrokerageID())); } In this example it would filter users who are a member of a specific brokerage only (each user has one brokerage). As you can see I can easily join other tables that are associated in the

Using JPA CriteriaBuilder to generate query where attribute is either in a list or is empty

房东的猫 提交于 2019-12-11 04:53:13
问题 I am trying to use the JPA CriteriaBuilder to generate a query for an entity called "TestContact" that has a many-to-many join with another entity called "SystemGroup" where the attribute for this join called "groups". The objective of the query is to retrieve records from the "TestContact" entity where the "groups" attribute is either in a list or is empty. The code I'm using is as follows public List<TestContact> findWithCriteriaQuery(List<SystemGroup> groups) { CriteriaBuilder cb = em