criteria

What are the alternatives to using an ORDER BY in a Subquery in the JPA Criteria API?

喜你入骨 提交于 2021-02-18 22:01:57
问题 Consider the following two tables: Project ( id, project_name) Status ( id, id_project, status_name) Where Status contains all statuses in which a Project has been. Lets say we want to query all projects for which the latest status has the name "new". The Sql query that I come up with is: SELECT q.id_project FROM status q WHERE q.status_name like 'new' AND q.id IN ( SELECT TOP 1 sq.id from status sq WHERE q.id_project = sq.id_project ORDER BY sq.id DESC ) I'm trying to replicate the above

What are the alternatives to using an ORDER BY in a Subquery in the JPA Criteria API?

末鹿安然 提交于 2021-02-18 22:00:39
问题 Consider the following two tables: Project ( id, project_name) Status ( id, id_project, status_name) Where Status contains all statuses in which a Project has been. Lets say we want to query all projects for which the latest status has the name "new". The Sql query that I come up with is: SELECT q.id_project FROM status q WHERE q.status_name like 'new' AND q.id IN ( SELECT TOP 1 sq.id from status sq WHERE q.id_project = sq.id_project ORDER BY sq.id DESC ) I'm trying to replicate the above

Specfiy columns which should be considered for distinct calculation

孤街醉人 提交于 2021-02-18 12:18:12
问题 I'm using javax.persistence.criteria.CriteriaBuilder and javax.persistence.criteria.CriteriaQuery to select some entities. I now want to select only the entities that are unique which should be specified by a certain column. There is the method javax.persistence.criteria.CriteriaQuery#distinct which only returns unique entities. I would rather need something like CriteriaQuery<T> distinct(String... columnNames) Do you know how I can bake such a distinct in my JPA CriteriaQuery ? It seems to

JPA Criteria API. Query with sql function call which takes parameters

心不动则不痛 提交于 2021-02-18 06:53:26
问题 I'm trying to construct this query using Criteria typesafe API: select * from xxx_table xxx where CALC_DISTANCE(xxx.latitude, xxx.longitude, :lat, :lng) < :dist CALC_DISTANCE definded PL/SQL function: FUNCTION calc_distance( pLat1 NUMBER, pLon1 NUMBER, pLat2 NUMBER, pLon2 NUMBER) RETURN NUMBER CriteriaBuilder builder = JpaHandle.get().getCriteriaBuilder(); CriteriaQuery<XXX> criteria = builder.createQuery(XXX.class); Root<XXX> xxxRoot = criteria.from(XXX.class); ParameterExpression<Double>

Hibernate Restrictions / Criteria Beginner Question

萝らか妹 提交于 2021-02-10 03:59:43
问题 Hi I have been trying to work out the best way to do this today to no avail. What I would ideally like to do is to create an alias distance calculated by the SQL formula below (although I am open to other ways of calculating the distance, this was just the way that seemed it should be easiest) Once I have that alias I want to be able to use it in a Restrictions fashion to find all that are within a certain distance. I would also like to be able to sort via distance. This is part of a bigger

Hibernate Restrictions / Criteria Beginner Question

最后都变了- 提交于 2021-02-10 03:58:07
问题 Hi I have been trying to work out the best way to do this today to no avail. What I would ideally like to do is to create an alias distance calculated by the SQL formula below (although I am open to other ways of calculating the distance, this was just the way that seemed it should be easiest) Once I have that alias I want to be able to use it in a Restrictions fashion to find all that are within a certain distance. I would also like to be able to sort via distance. This is part of a bigger

Hibernate Restrictions / Criteria Beginner Question

Deadly 提交于 2021-02-10 03:57:40
问题 Hi I have been trying to work out the best way to do this today to no avail. What I would ideally like to do is to create an alias distance calculated by the SQL formula below (although I am open to other ways of calculating the distance, this was just the way that seemed it should be easiest) Once I have that alias I want to be able to use it in a Restrictions fashion to find all that are within a certain distance. I would also like to be able to sort via distance. This is part of a bigger

hibernate criteria count over with group by

本秂侑毒 提交于 2021-02-02 09:37:26
问题 I have a spring app with the user entity and the users table. I would like to get a number of all users grouped by certain fields (not per group but in total ). In sql It would be: select count(*) OVER () as totalRecords from users u group by u.first_name, u.last_name, u.age order by u.age DESC OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY; But I really can't do that using hibernate criteria. I could do something like: public Long getTotalCount() { ProjectionList groupBy = projectionList(); groupBy

hibernate criteria count over with group by

做~自己de王妃 提交于 2021-02-02 09:35:52
问题 I have a spring app with the user entity and the users table. I would like to get a number of all users grouped by certain fields (not per group but in total ). In sql It would be: select count(*) OVER () as totalRecords from users u group by u.first_name, u.last_name, u.age order by u.age DESC OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY; But I really can't do that using hibernate criteria. I could do something like: public Long getTotalCount() { ProjectionList groupBy = projectionList(); groupBy

hibernate criteria count over with group by

北战南征 提交于 2021-02-02 09:31:33
问题 I have a spring app with the user entity and the users table. I would like to get a number of all users grouped by certain fields (not per group but in total ). In sql It would be: select count(*) OVER () as totalRecords from users u group by u.first_name, u.last_name, u.age order by u.age DESC OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY; But I really can't do that using hibernate criteria. I could do something like: public Long getTotalCount() { ProjectionList groupBy = projectionList(); groupBy