hql

Proper way of writing a HQL in ( … ) query

不打扰是莪最后的温柔 提交于 2019-12-18 10:22:17
问题 Assuming that I want to write the following HQL query: FROM Cat c WHERE c.id IN (1,2,3) what is the proper way of writing this as a parametrized query, e.g. FROM Cat c WHERE c.id IN (?) 回答1: I am unsure how to do this with positional parameter, but if you can use named parameters instead of positional, then named parameter can be placed inside brackets and setParameterList method from Query interface can be used to bind the list of values to this parameter. ... Query query = session

Hibernate filtering query collections

。_饼干妹妹 提交于 2019-12-18 09:17:20
问题 I would like to ask if it's possible to do this using hibernate. Let say I have already run a HQL and retrieved a collection. Is it possible to further filter it using hibernate? I tried to use the <filter> to the header class and add session.enable() before the query, but seems it's not working. Sample code Query search = session.getNamedQuery(HQL_SOMEDEFAULTQUERY); List results = search.list(); //further filtering ... Stripped down HQL select h from flow as f join f.item as i join i.header

Hibernate + MSSQL + Fulltext Search via Contains

跟風遠走 提交于 2019-12-18 09:10:17
问题 My goal is to use the MSSQL Fulltext Function with HQL. For what case I wrote a specific SQLFunction mapping the my "fulltext" function to the contains function. However, the problem is that in HQL (it seems) I have to explicity use a return type, which the MSSQL Contains functions does not use or accepts. This is how it works in MSSQL: select distinct id from content c where CONTAINS(c.content, 'p') This is my idea of using it in HQL: select id from Content c where fulltext(c.content, 'p')

Custom SQL function for NHibernate dialect

醉酒当歌 提交于 2019-12-18 08:27:31
问题 I want to be able to call a custom function called "recent_date" as part of my HQL. Like this: [Date] >= recent_date() I created a new dialect, inheriting from MsSql2000Dialect and specified the dialect for my configuration. public class NordicMsSql2000Dialect : MsSql2000Dialect { public NordicMsSql2000Dialect() { RegisterFunction( "recent_date", new SQLFunctionTemplate( NHibernateUtil.Date, "dateadd(day, -15, getdate())" ) ); } } var configuration = Fluently.Configure() .Database(

@Query annotation using like %?1%

≡放荡痞女 提交于 2019-12-18 06:59:09
问题 I'd like to write a query like this @Query("select p from Product p where p.name = ?1 or p.desc like %?1%") but it gives me the exception org.hibernate.hql.ast.QuerySyntaxException: unexpected token: % near line 1, I tried replacing % with '%' or concatenating the query string like this: "select ... like '%'" + "?1" + "'%'" but with no luck, please help me 回答1: If you are using Spring Data JPA version 1.3.1 or later you need to do the following: @Query("select p from Product p where p.name =

Can I eager load a property using HQL?

依然范特西╮ 提交于 2019-12-18 06:48:24
问题 I'm trying to work out how to eager load the customers in the following HQL query: select order.Customer from Order as order where order.Id in ( select itemId from BadItem as badItem where (badItemType = :itemType) and (badItem.Date >= :yesterday) ) There's the usual many-to-one relationship between orders and customers. I'd like to do this is in the query, as opposed to the mapping, if possible - as in a "join fetch..." Maybe the query would be refactored as a join and I'm having a mental

Nhibernate HQL where IN query

纵饮孤独 提交于 2019-12-18 04:39:04
问题 Im trying to return a SimpleQuery list that queries a single table and uses IN. I can get this to work using return new List<Jobs>( ActiveRecordMediator<Jobs>.FindAll(Expression.In("ServiceId", ids)) ); However this is really really really slow. So id like to do something like this SimpleQuery<Job> query = new SimpleQuery<Job>(@"from Job as j where ? in (j.ServiceId)", ids); return new List<Job>(query.Execute()); However I cant get the SimpleQuery to work. I cant find any documentation

How to write a like query in HQL [duplicate]

怎甘沉沦 提交于 2019-12-18 04:33:26
问题 This question already has answers here : Using LIKE % in Hibernate (3 answers) Closed 2 years ago . I want to perform search for a particular string that is starting with a particular alphabet. So, for example if the starting alphabet is 'A' den it should produce a result which will contain all the strings with alphabet 'A' . How do I achieve this ? My query is as shown below Query qry = session.createQuery("From RegistrationBean as rb where rb."+searchCriteria+" like %?%"); qry.setString(0

Why can't hive recognize alias named in select part?

此生再无相见时 提交于 2019-12-18 03:22:48
问题 Here's the scenario: When I invoke hql as follows, it tells me that it cannot find alias for u1. hive> select user as u1, url as u2 from rank_test where u1 != ""; FAILED: SemanticException [Error 10004]: Line 1:50 Invalid table alias or column reference 'u1': (possible column names are: user, url) This problem is the same as when I try to use count(*) as cnt . Could anyone give me some hint on how to use alias in where clause? Thanks a lot! hive> select user, count(*) as cnt from rank_test

How to retrieve only certain fields of an entity in JPQL or HQL? What is the equivalent of ResultSet in JPQL or HQL?

自古美人都是妖i 提交于 2019-12-17 23:06:36
问题 In JPQL, I can retrieve entities by : query = entityManager.createQuery("select c from Category c"); List<Category> categories = query.getResultList(); But, if I wish to retrieve the id and name fields (only) of the Category entity, I need something like the ResultSet object, through which I can say : rs.getString("name") and rs.getString("id") . How to do this through JPQL , without retrieving the entire entity ? Basically, for a how to retrieve information from a query like : select c.id,c