hql

HQL - difference between two same queries

感情迁移 提交于 2020-01-06 05:40:08
问题 Why does this query work normal: Query query = session.createQuery("from Table tab"); And this query: Query query = session .createQuery("select tab.col1, tab.col2, tab.col3 from Table tab"); And that's what I'm doing with both queries: dataList = query.list(); for (Table item : dataList) { System.out.println(item.getCol1(); } reports: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to table.Table at test.TestCriteria.main(TestCriteria.java:35) Could you help? Table is

Remotefunction not working

谁说我不能喝 提交于 2020-01-05 09:22:43
问题 Below is my Pgtyp.groovy (domain class): package marchmock2 class Pgtyp { Date date_hour String mv String pagetype Integer visits Integer visits_ly Integer visits_lw String time_period String platform String device String browser static mapping = { table "pgtyp" version false date_hour column: "date_hour" mv column: "mv" pagetype column: "pagetype" visits column: "visits" visits_ly column:"visits_ly" visits_lw column:"visits_lw" time_period column:"time_period" platform column:"platform"

How to check if a pair exists using HQL in query?

杀马特。学长 韩版系。学妹 提交于 2020-01-05 08:43:11
问题 I have a list of different ids and their names. For every id[0] we have name[0] that needs to be matched. list of ids, l{1,2,3,4}; list of names, n{a,b,c,d}; Now suppose if I want to get an exact match for both above combination, is there any way in HQL to get the result? I am looking to find a replacement for a query like: select any_column from table_name where (id[0]=1 and name[0]=a) or (id[1]=2 and name[1]=b and so on...); The HQL query should be something like below: select any_column

How to check if a pair exists using HQL in query?

和自甴很熟 提交于 2020-01-05 08:43:04
问题 I have a list of different ids and their names. For every id[0] we have name[0] that needs to be matched. list of ids, l{1,2,3,4}; list of names, n{a,b,c,d}; Now suppose if I want to get an exact match for both above combination, is there any way in HQL to get the result? I am looking to find a replacement for a query like: select any_column from table_name where (id[0]=1 and name[0]=a) or (id[1]=2 and name[1]=b and so on...); The HQL query should be something like below: select any_column

Search records having comma seperated values that contains any element from the given list

随声附和 提交于 2020-01-05 07:48:22
问题 I have a domain class Schedule with a property 'days' holding comma separated values like '2,5,6,8,9'. Class Schedule { String days ... } Schedule schedule1 = new Schedule(days :'2,5,6,8,9') schedule1.save() Schedule schedule2 = new Schedule(days :'1,5,9,13') schedule2.save() I need to get the list of the schedules having any day from the given list say [2,8,11]. Output: [schedule1] How do I write the criteria query or HQL for the same. We can prefix & suffix the days with comma like ',2,5,6

Caused by: org.hibernate.QueryException: Not all named parameters have been set: [isActive] [from User where isActive = :isActive]

醉酒当歌 提交于 2020-01-05 04:23:07
问题 I have a table of users made up of a boolean value of active users as shown in the following table id | name | active 1 | john | false 2 | bob | true 3 | jeff | true On the above structure, I want to retrieve the list of users where isActive is equal to true. This is my hql query public List getByIsActive(boolean isActive) { return getSession().createQuery( "from User where isActive = :isActive").list(); } I am retrieving it like this @ResponseBody @RequestMapping(value = "/get-all

How to return Map<Key, Value> with Hibernate\HQL

旧城冷巷雨未停 提交于 2020-01-05 03:18:29
问题 I have an entry as follow: @Entity @Table(name="rank") class Rank implements Serializable { private int id; private int rank_id; private date creationDate; ... // getters\setters... } I would like to query this table and put the results into a HashMap! as follow: Map<Integer, Rank> = session.createSQL("select new map...").list(); Is this possible to put the entity as the value of the map? Can I get a code example? 回答1: Yes, for example: Select new Map(r.id,r) FROM Rank r But that will return

Using functions as arguments in hibernate aggregation functions

房东的猫 提交于 2020-01-04 06:51:34
问题 I would like to perform the following query in HQL: select count(distinct year(foo.date)) from Foo foo However, this results in the following exception: org.hibernate.hql.ast.QuerySyntaxException: expecting CLOSE, found '(' near line 1, column 27 It seems that hibernate does not allow using functions as arguments to its aggregation functions. Is there any way to get the required result? 回答1: Select the whole date Loop over the result and extract a new collection made of the year from each

Hibernate query filter on collection

*爱你&永不变心* 提交于 2020-01-04 05:42:13
问题 I want to execute following query: from Item i where i.categoryItems.catalogId = :catId That however yields in following exception: illegal attempt to dereference collection So I googled, found this Hibernate forum post https://forum.hibernate.org/viewtopic.php?p=2349920 that recommended me to do the following: from Item i, IN (i.categoryItems) WHERE i.catalogId = :catId This kind of works, but there's a problem with this: It returns me an Object array with Item object and CategoryItem object

Hibernate LeftOuter join HQL

本小妞迷上赌 提交于 2020-01-04 05:32:46
问题 This is my left join hql query. After executing this code i am getting list size. But unable cast object to respective pojo class. Query query=session.createQuery("from BwClientdetails client left join client.bwClientAllocations"); System.out.println(">>>"+query.list().size()); List<BwClientdetails> list=query.list(); for(int i=0;i<list.size();i++){ BwClientdetails bc=list.get(i); System.out.println(bc.getClientid()); } I am getting below error: java.lang.ClassCastException: [Ljava.lang