hql

Compare LocalDate with LocalDateTime in HQL/JPQL

…衆ロ難τιáo~ 提交于 2021-02-11 14:53:24
问题 Is it possible to compare LocalDate with LocalDateTime in HQL/JPQL? This is my query of repository method in spring data which should return amount of orders per required dates. The field deliveryDateTime in Order entity has type LocalDateTime . I want to ignore time part and compare only date part. @Query("SELECT new OrderCountPerDate(DATE(o.deliveryDateTime), COUNT(o.id)) FROM Order o WHERE DATE(o.deliveryDateTime) IN :dates GROUP BY DATE(o.deliveryDateTime) ") List<LocalDate>

HQL unexpected token “(” subquery select

五迷三道 提交于 2021-02-11 13:50:21
问题 I have this query. Translate it from my sql query to hql. I have this error "unexpected token: ( near line 2, column" String query = "SELECT MAX(number)\n" + " FROM (SELECT number FROM EmployeeTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM PostgraduateTripCard\n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM StudentTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) =

Hibernate query to filter results from a nested object list

戏子无情 提交于 2021-02-10 14:14:52
问题 As a followup to this answer(on approach 1 ) I want to go a step further : I want to Filter the grand child objects based on certain criteria's. I tried the following query, but it still does not filter out the objects under the grandchild entity. @Query("select ch from ChildEntity ch " + " join ch.parentEntity pr " + " join fetch ch.grandChildEntities gc " + " where pr.bumId = :bumId and ch.lastExecutionTimestamp in " + "( select max(ch1.lastExecutionTimestamp) from ChildEntity ch1 " + "join

Hibernate exception. QuerySyntaxException: unexpected token: HAVING

为君一笑 提交于 2021-02-08 11:24:20
问题 I try use this HQL query: Result.find("SELECT c, ( 3959 * acos( cos( radians(?) ) * "+ "cos( radians( c.latitude ) ) *"+ "cos( radians( c.longitude ) - radians(?) ) +"+ "sin( radians(?) ) * sin( radians( c.latitude ) ) ) ) " + "AS distance FROM City c HAVING distance < ? ORDER BY distance ASC", latitude, longitude, latitude, radius).fetch(); But in result: IllegalArgumentException occured : org.hibernate.hql.ast.QuerySyntaxException: unexpected token: HAVING near line 1, column 204 [SELECT c,

HQL query to select data between two dates not returning any record

落爺英雄遲暮 提交于 2021-02-08 11:22:49
问题 ReportView I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo. I've tried, (1) List list = session.createQuery("from ReportView where date between :stDate and :edDate") .setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault())))) .setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault())))) .list(); (2) SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

HQL query to select data between two dates not returning any record

两盒软妹~` 提交于 2021-02-08 11:21:38
问题 ReportView I'm getting values of Dates from JavaFX DatePicker objects tDateFrom, tDateTo. I've tried, (1) List list = session.createQuery("from ReportView where date between :stDate and :edDate") .setTimestamp("stDate", Date.from(Instant.from(tDateFrom.getValue().atStartOfDay(ZoneId.systemDefault())))) .setTimestamp("edDate", Date.from(Instant.from(tDateTo.getValue().atStartOfDay(ZoneId.systemDefault())))) .list(); (2) SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

extracting a substring from a text column in hive

喜你入骨 提交于 2021-02-08 10:04:42
问题 We have text data in a column named title like below "id":"S-1-98-13474422323-33566802","name":"uid=Xzdpr0,ou=people,dc=vm,dc=com","shortName":"XZDPR0","displayName":"Jund Lee","emailAddress":"jund.lee@bm.com","title":"Leading Product Investor" Need to extract just the display name (Jund lee in this example) from the above text data in hive, I have tried using substring function but don't seem to work,Please help 回答1: Use regexp_extract function with the matching regex to capture only the

JPA: TypedQuery sometimes returns null instead of NoResultException

房东的猫 提交于 2021-02-07 12:35:27
问题 Usually I work with NoResultException to return an "empty" object, e.g. an empty error list or new BigInteger("0"), if I get no results from a TypedQuery. Now it turned out that this sometimes doesn't work. Suddenly getSingleResult() returns null instead of causing a NoResultException, and I don't understand why. Look this example: public BigInteger pointsSumByAccountId(long accountId) { try { TypedQuery<BigInteger> pointsQuery = entityManager.createNamedQuery(Points.SumByAccountId,

rewrite SQL query to HQL

被刻印的时光 ゝ 提交于 2021-01-29 20:19:32
问题 I've SQL query: SELECT tag.id, tag.description, tag.`name`, COUNT(question_has_tag.question_id) FROM question_has_tag INNER JOIN question ON question.id = question_has_tag.question_id INNER JOIN tag ON question_has_tag.tag_id = tag.id GROUP BY tag.id All works good. But I need to rewrite it to HQL, some one have any idea? I tried this, but it doesn't work: list = entityManager.createQuery("SELECT " + "t.id, " + "t.description, " + "t.name, " + "COUNT(q.id) " + "FROM Tag t INNER JOIN Question

rewrite SQL query to HQL

烂漫一生 提交于 2021-01-29 16:51:48
问题 I've SQL query: SELECT tag.id, tag.description, tag.`name`, COUNT(question_has_tag.question_id) FROM question_has_tag INNER JOIN question ON question.id = question_has_tag.question_id INNER JOIN tag ON question_has_tag.tag_id = tag.id GROUP BY tag.id All works good. But I need to rewrite it to HQL, some one have any idea? I tried this, but it doesn't work: list = entityManager.createQuery("SELECT " + "t.id, " + "t.description, " + "t.name, " + "COUNT(q.id) " + "FROM Tag t INNER JOIN Question