hql

How to pass parameter in HQL query

感情迁移 提交于 2019-12-20 02:56:48
问题 find below my HQL query Query query = session.createQuery("select u from UserLog u where u.userLogSerialno = " + "(select max(uu.userLogSerialno) from UserLog uu where uu.userId = u.userId)"); This query is working fine but in this, I want to pass the value of userId but I am not able to figure out how to do this. Kindly Help..!! Thanks in Advance..!! 回答1: I is very simple to add parameter to an HQL Query query = session.createQuery("select u from UserLog u where u.userLogSerialno = " + "

how to use string left function in hql

北城余情 提交于 2019-12-20 02:37:21
问题 I have a sql query like this select column from table where path = left('INPUTSTRING', length(path)); and trying to accomplish it in hql like this, return session.createQuery("from Table where Path = left(:input, length(Path))"). query.setParameter("input", inputPath). .list(); and getting an error like this Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: left near line 1 how to get this done? What is the corresponding string function in hql? Is there a solution for

HQL with parameters NoSuchMethodError

故事扮演 提交于 2019-12-19 08:09:12
问题 I am sure I am overlooking something obvious the following static query works fine hqlQuery = "select user from User as user where user.id = 'userid' "; but when I parametrize the query hqlQuery = "select user from User as user where user.id = :me "; Query query = session.createQuery(hqlQuery); I get a nasty stack dump from building the query. What am I overlooking? Exception in thread "main" java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I at org.hibernate.hql.ast.HqlSqlWalker

Hibernate query date compare on year and month only

半城伤御伤魂 提交于 2019-12-19 03:42:11
问题 I need to grab some records from a table which has a Column birthDate which is a Date (without time). I need to filter records by comparing against year and month only. For example I want all the users born on March of 1990. The day doesn't matter. How do you handle it? 回答1: You can use from Entity where to_char(birthDate,'YYYY/MM') = '1990/03' this will work for HQL 回答2: you may try this select * from table where month(birthdate)=03 and year(birthdate)=1990 来源: https://stackoverflow.com

why does hibernate hql distinct cause an sql distinct on left join?

别等时光非礼了梦想. 提交于 2019-12-18 20:51:40
问题 I've got this test HQL: select distinct o from Order o left join fetch o.lineItems and it does generate an SQL distinct without an obvious reason: select distinct order0_.id as id61_0_, orderline1_.order_id as order1_62_1_... The SQL resultset is always the same (with and without an SQL distinct): order id | order name | orderline id | orderline name ---------+------------+--------------+--------------- 1 | foo | 1 | foo item 1 | foo | 2 | bar item 1 | foo | 3 | test item 2 | empty | NULL |

Hibernate HQL query by using like operator

…衆ロ難τιáo~ 提交于 2019-12-18 18:53:50
问题 Seu the following mapping @Entity public class User { private Integer id; @Id; private Integer getId() { return this.id; } } Notice id is an Integer. Now i need this HQL query by using like operator Query query = sessionFactory.getCurrentSession().createQuery("from User u where u.id like :userId"); ATT: IT IS like operator NOT = (equals operator) Then i use List<User> userList = query.setParameter("userId", userId + "%").list(); But does not work because Hibernate complains

Hibernate 4.3.6 QuerySyntaxException: Path expected for join

a 夏天 提交于 2019-12-18 17:26:33
问题 Am having problem with HQL join query. Can anyone tell me whats wrong with my below join HQL query? Am using Hibernate 4.3.6, JDK 7 and Groovy 2.2 def query = 'select lip.referenceId from Parcel as lip left join TransportFile tf where lip.statusDisplayName != tf.statusDisplayName' def hqlQuery = session.createQuery(query) def hqlcount = hqlQuery.list().size Am getting the below error when i run above code com.dc.core.common.exception.BaseApplicationException: org.hibernate.hql.internal.ast

HQL how to query ElementCollection of String

拜拜、爱过 提交于 2019-12-18 13:30:04
问题 I have class like public User{ Long id; Set<String> roles; } How do I query all User objects with the role of "ADMIN" EDIT: I'm using Hibernate 3.0.5. And have tried most of the obvious approaches. from Users where roles in('ADMIN') gives a JDBC error. from Users u where u.roles in('ADMIN') gives a class cast exception I think this may be a problem with this particular version of hibernate. 回答1: I've found solution: "from User as user where 'ADMIN' in elements(user.roles)"; Somehow hql

HQL left join: Path expected for join

删除回忆录丶 提交于 2019-12-18 11:51:12
问题 I am new at Hibernate, and I have a question regarding HQL Left join. I try to left join 2 tables, patient and provider, and keep getting "Path expected for join!" error on the second table. Appreciate it if anybody can help on this issue! Here is the mapping of the 2 tables/classes: patient.hbm.xmL: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com

org.hibernate.QueryException: illegal attempt to dereference collection

淺唱寂寞╮ 提交于 2019-12-18 10:37:54
问题 I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference collection [billdetail0_.bill_no.billProductSet] with element property reference [product] [select count(*) from iland.hbm.BillDetails as bd where bd.billProductSet.product.id=1001 and bd.client.id=1] at org.hibernate.hql.ast.tree.DotNode$1