hql

HQL substring last x characters

瘦欲@ 提交于 2019-12-11 07:57:33
问题 I am quite new to Hibernate, and I would like to get the last N characters of a string. I found the substring method, but that didn't really help :( Does anyone have any idea? TIA 回答1: I actually fixed it using substring. I forgot that I can use parameters. I did something like: Query q = " .. where substring (field, :offset, :length) = something_else" q.setParameter("offset", field.length() - N + 1); q.setParameter("length", N); 回答2: I am surprised this didn't help substring(int beginIndex,

Does NHibernate HQL support the UNION ALL keyword?

旧巷老猫 提交于 2019-12-11 07:37:46
问题 After extensive googling, I still can't find a definitive answer to this question. Some old articles/blog posts I've seen say not at all. Some say yes if the underling database supports it. Which is it? I asked on the nhusers group with no answer so far. Any help would be appreciated. 回答1: NHibernate does not support union. There is always one type in a result. What you can do is a query to a base class or interface. NHibernate will perform a union to get all the values from all tables where

How to convert MySQL query into HQL query?

好久不见. 提交于 2019-12-11 07:08:53
问题 I am new to HQL. This is a mysql Query. I need to convert it into HQL query. How to do that any suggestions please? `SELECT STUDENT.ID, STUDENT.NAME, STUDENT.GRADE_ID, STUDENT.CLASS, GRADE.NAME FROM STUDENT INNER JOIN GRADE ON STUDENT.GRADE_ID = GRADE.GRADE_ID` STUDENT[ID, NAME, GRADE_ID, CLASS] GRADE[GRADE_ID, GRADE_NAME] The resultset of the above query will be something like ID, NAME, GRADE_NAME, CLASS. Final Update: I have 2 tables STUDENT[ID, NAME, GRADE_ID, CLASS] GRADE[GRADE_ID, GRADE

org.hibernate.hql.ast.QuerySyntaxException: unexpected token

落花浮王杯 提交于 2019-12-11 06:57:21
问题 I'm working with Struts2 and Hibernate and I'm getting this error : org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 61 [SELECT s.codeOracle FROM sites as s INNER JOIN contrat as c on c.idSite = s.idSite INNER JOIN paiement as p on p.idcontrat = c.idcontrat INNER JOIN periodepay as pp on pp.idPaiement = p.idPaiement WHERE pp.statutPay = 1 group by s.codeOracle] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org

Basic date/time manipulation in NHiberate query

≡放荡痞女 提交于 2019-12-11 06:56:27
问题 I'm trying to restrict my NHibernate query with some basic date/time manipulation . More specifically, I want to execute the following statement (pseudo-SQL): select * from article where created_on + lifespan >= sysdate with: created_on is mapped to a property of type DateTime . lifespan is mapped to a property of type TimeSpan . sysdate is the current date/time (of the database server or ofthe application host, I don't care) Is there any built-in way to do that by using the Criteria-API or

Hibernate: how to select last N rows in ascending order of id? (in single query)

ぐ巨炮叔叔 提交于 2019-12-11 06:05:22
问题 Hibernate version: 5.2 I am trying to use subqueries to do, and use setMaxResults(int). session.createQuery( "FROM ( SELECT * FROM tickets ORDER BY id DESC limit 3) sub ORDER BY id ASC" ); However, HQL subqueries can occur only in the select or where clauses, and limit can't be used in hibernate. How can I do it in hibernate? Update - To make it clear For eg, there are 10 data entries from id=1 to id=10. I want to select last 3 data in ascending order of id by only one query + without further

HQL update query

一世执手 提交于 2019-12-11 05:34:10
问题 I've got problem to exceute one update-HQL-query. I want to edit values saved in profile entity, but with no luck. my entities looks like below @Entity @Table(name = "users", catalog = "testdb") public class UserEntity implements java.io.Serializable { private Integer id; private String username; private String password; private Profile profile; @OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL) public Profile getProfile() { return this.profile; } public void

How do I turn item ordering HQL into a filter query?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 05:01:02
问题 I have this query: sess.createQuery("from Box b join b.items bi order by bi.name").list() It works fine. However, I have a hibernate's Collection boxes and want to filter is. Naive tries: sess.createFilter(boxes, "join this.items bi order by bi.name").list() sess.createFilter(boxes, "from this join this.items bi order by bi.name").list() don't work! What's the proper way to convert this HQL to filter? 回答1: Try... session.createFilter(items.getBoxes(), "order by this.name").list() 回答2: When

NHibernate Insert into … select … with GUID as PrimaryKey

二次信任 提交于 2019-12-11 04:49:39
问题 I try to do fallowing with NHibernate: this.Session.CreateQuery(@"insert into ContactGroupContact (Id, MailAddress, Company, Person, Branch, ContactGroup, User, FaxNumber) select newid(), MailAddress, Company, Person, Branch, :destContactGroupId, User, FaxNumber from ContactGroupContact cgc where cgc.ContactGroup.Id = :contactGroupId") .SetEntity("destContactGroupId", tempContactGroup) .SetGuid("contactGroupId", contactGroupId) .ExecuteUpdate(); The column Id of ContactGroupContact is of type

hive SQL(HQL)葵花宝典

只谈情不闲聊 提交于 2019-12-11 04:47:19
hive SQL(HQL)葵花宝典 1. 基本数据类型 2.基础运算符与函数 3. 内置运算符 3.1关系运算符 3.2算术运算符 3.3逻辑运算符 3.4复杂类型函数 4.类型转换n 5.日期函数 5.1取年月日时分秒(格式化) 5.2获取今天时间(格式可以自定义) 5.3计算年龄 5.4年月日拼接 5.5总结 6.条件函数 7.常用字符串函数 1. 基本数据类型 tinyint , smallint, int, bigint, float, double, boolean: true/false, string 2.基础运算符与函数 A IS NULL 空 A IS NOT NULL 非空ro A LIKE B 模糊匹配 A RLIKE B 正则表达式匹配 A REGEXP B 正则表达式匹配 SELECT '211' REGEXP '\\d.+', '211' REGEXP '\\D.+', 'abc' REGEXP '\\d.+', 'abc' REGEXP '\\D.+' 运行结果 true false false true 3. 内置运算符 3.1关系运算符 3.2算术运算符 3.3逻辑运算符 3.4复杂类型函数 待定 4.类型转换n cast(expr as <type>) 例如: cast('1' as BIGINT) 将字符串'1'转化成bigint型 5