hql

how to return Map<Key, Value> with HQL

人走茶凉 提交于 2019-12-17 06:37:21
问题 i have a table Permission : id name desc what i am doing right now is to make a query that returns a permission object then put the values in the map programmatically 1- But i was wondering if it's possible to make an HQL (or native sql if not possible) to select the permission_id , permission_name and return them in a map. 2- is it possible to return map in one to many relationship instead of following list or set @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name

IN-clause in HQL or Java Persistence Query Language

时间秒杀一切 提交于 2019-12-17 06:25:35
问题 I have the following parametrised JPA, or Hibernate, query: SELECT entity FROM Entity entity WHERE name IN (?) I want to pass the parameter as an ArrayList<String>, is this possible? Hibernate current tells me, that java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String Is this possible at all? ANSWER : Collections as parameters only work with named parameters like " :name ", not with JDBC style parameters like " ? ". 回答1: Are you using Hibernate's Query object,

How do you create a Distinct query in HQL

感情迁移 提交于 2019-12-17 03:02:41
问题 Is there a way to create a Distinct query in HQL. Either by using the "distinct" keyword or some other method. I am not sure if distinct is a valid keywork for HQL, but I am looking for the HQL equivalent of the SQL keyword "distinct". 回答1: Here's a snippet of hql that we use. (Names have been changed to protect identities) String queryString = "select distinct f from Foo f inner join foo.bars as b" + " where f.creationDate >= ? and f.creationDate < ? and b.bar = ?"; return

Difference between JOIN and JOIN FETCH in Hibernate

為{幸葍}努か 提交于 2019-12-17 02:02:54
问题 Please help me understand where to use a regular JOIN and where a JOIN FETCH. For example, if we have these two queries FROM Employee emp JOIN emp.department dep and FROM Employee emp JOIN FETCH emp.department dep Is there any difference between them? If yes, which one to use when? 回答1: In this two queries, you are using JOIN to query all employees that have at least one department associated. But, the difference is: in the first query you are returning only the Employes for the Hibernate. In

Select collections with HQL

六眼飞鱼酱① 提交于 2019-12-14 03:49:33
问题 I have the following classes: Person.java class Person { String name; Set<Hotel> visitedHotels; String someOtherData; public Person() {} public Person(String name, Set<Hotel> visitedHotels) { this.name; this.visitedHotels = this.visitedHotels; } // getters & setters } Hotel.java class Hotel { // some code } For security reasons "someOtherData" should sometimes not be loaded. So I tried the following HQL: select new Person( p.name , elements(p.visitedHotels) ) from Person p or select new

HQL Order by query giving problem

≯℡__Kan透↙ 提交于 2019-12-14 03:28:23
问题 I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as ret_name, ret.id.retailerId as ret_id, ret.id.serviceId as service_id, (select count(distinct i.inspectionId) as inspections from Inspection i inner join i.clgCodeStatus c inner join c.retailerOrderses r inner join r.cusRetailer cr inner join i.inspectionMission m where ret.id = cr.id ) as inspections , (select count(distinct i

Doesn't session.get() in hibernate always hit the database?

纵然是瞬间 提交于 2019-12-14 03:18:47
问题 Theoretically, session.get() method is supposed to hit the database always, no matter whether the entity is stored in the cache or not. But whenever I use session.get() or session.load(), both doesn't hit the database second time. Session session = factory.openSession(); tx = session.beginTransaction(); Customer cust = (Customer)session.get(Customer.class,2); System.out.println(cust.getCid()+","+cust.getFirstName()+","+cust.getLastName()+","+cust.getPhone()); Customer cust2 = (Customer

JPA/Hibernate + HQL/JPQL: select DTO with BigDecimal parameter

独自空忆成欢 提交于 2019-12-14 02:34:08
问题 We are using JPA with hibernate as the implementation. Suppose I have the following DTO: public class SupplierInfoDto{ private String supplierName; private BigDecimal remainingFinances; public SupplierInfoDto(String supplierName, BigDecimal remainingFinances){ this.supplierName = supplierName; this.remainingFinances = remainingFinances; } // getters / setters } I cannot seem to get hibernate to properly find this constructor. I first tried the following query (the model is more complicated

hibernate one to many query using mappings

眉间皱痕 提交于 2019-12-14 02:26:58
问题 I have 3 classes with the corresponding relationship parent child on them: //SigTcContraloriaObjetivos, SigTcContraloriaIniciativas, SigTcContraloriaAcciones <class dynamic-insert="false" dynamic-update="true" mutable="true" name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaObjetivos" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="SIG_TC_CONTRALORIA_OBJETIVOS"> <id column="ID_OBJETIVO" name="idObjetivo"> <generator class=

How to order by count desc in each group in a hive?

▼魔方 西西 提交于 2019-12-14 00:19:03
问题 Here's the HQL: select A, B, count(*) as cnt from test_table group by A, B order by cnt desc; The sample output is as follows: a1 | b1 | 5 a2 | b1 | 3 a1 | b2 | 2 a2 | b2 | 1 But what I want is to do the order by in each group of A, and the intended output is like: a1 | b1 | 5 a1 | b2 | 2 a2 | b1 | 3 a2 | b2 | 1 Could anyone can give me some idea how to resolve this problem in just one HQL? Thanks a lot! 回答1: select A, B, count(*) as cnt from test_table group by A, B order by A, cnt desc; 回答2