hql

How to use the MySQL CONVERT_TZ function in a JPQL or HQL query

谁说胖子不能爱 提交于 2020-01-14 13:46:11
问题 I currently have table in a MySQL database which has a startDate and endDate which are both timestamps . This is linked to the code using hibernate. I can return these by using the following HQL SELECT startDate, endDate FROM Reservation where id = :id What I am trying to do is return these dates based on a given timezone. I know MySQL has a function CONVERT_TZ which can return the dates based on a given timezone, I'm wondering if HQL has a similar function? I know HQL has a TIMESTAMP_WITH

Hive : reflect function

荒凉一梦 提交于 2020-01-14 04:00:37
问题 Im trying to use Reflect function of Hive which have this signature : reflect(class, method[, arg1[, arg2..]]) I want to ckeck if a column c with value hello world ! contains world , so I wrote : with a as (select "hello world !" as c) select reflect("java.lang.String",c ,"contains", "world") from a But it didnt work because it does not respect the signature, so i tried this with a as (select "hello world !" as c) select reflect(reflect("java.lang.Object","toString",c) ,"contains", "world")

Get nextval sequence value by simple java Query on a PostgreSQL DB

随声附和 提交于 2020-01-13 19:56:47
问题 I'm working on a PostgreSQL Database and I am trying to recover a nextval sequence by a simple Query by Java, but It's not working : Query q = entityManager.createQuery("SELECT nextval(numcallcartnewcart) as num"); BigDecimal result=(BigDecimal)q.getSingleResult(); return result.longValue(); (Of course it's not the best solution, but I can't do better, because I'm blocked by the Hibernate configuration with the composite-id tag which don't accept a generator sequence like that : <column name=

Get nextval sequence value by simple java Query on a PostgreSQL DB

偶尔善良 提交于 2020-01-13 19:56:31
问题 I'm working on a PostgreSQL Database and I am trying to recover a nextval sequence by a simple Query by Java, but It's not working : Query q = entityManager.createQuery("SELECT nextval(numcallcartnewcart) as num"); BigDecimal result=(BigDecimal)q.getSingleResult(); return result.longValue(); (Of course it's not the best solution, but I can't do better, because I'm blocked by the Hibernate configuration with the composite-id tag which don't accept a generator sequence like that : <column name=

Hibernate Query to fetch records on date ignoring timestamp

柔情痞子 提交于 2020-01-13 19:31:08
问题 I have a timestamp column tradedate in one of the DB(Oracle) tables. I am using hibernate as the persistence layer to fetch and store Data to DB. I have a requirement in which I need to query the DB on date. i.e From UI the user passes a date and I need to get the filtered data based on this date. If the tradedate column only has the date part my query returns the correct records The issue arises when the tradedate column is populated with a timestamp value ie(date + time). Then those values

Control sort order of Hibernate EnumType.STRING properties

淺唱寂寞╮ 提交于 2020-01-13 09:27:06
问题 Currently, my project uses @Enumerated(EnumType.ORDINAL) , so when I sort by this column, it is ordering based on the order in the enum , which works fine. But I need to add some additional values to the enum , which need to be inserted at different locations in the list of enum values and can't be just added to the bottom to maintain the correct sort order. If I do this, my database will be messed up. I'll have to write some scripts to translate all these ordinal values to the correct new

NHibernate: HQL and UserTypes as query parameters

拜拜、爱过 提交于 2020-01-13 04:11:51
问题 I'm using a database that has a weird date format. I wrote a UserType to transfer standard .NET DateTime to/from the weird format and it works fine. I've normally used ICriteria queries but decided to try IQuery using HQL on this project. I ran into a problem that query doesn't translate parameters to the appropriate UserType. eg: IQuery query = session.CreateQuery("from OfflineShipmentLineItem as line join fetch line.Shipment as shipment join fetch line.Extension where shipment.ShipmentDate

HQL练习

佐手、 提交于 2020-01-13 02:11:32
Hive学习笔记总结 05. Hql练习 1. hql基础练习 题目和数据来源: http://www.w2b-c.com/article/150326(去掉-) create和load create table students(Sno int,Sname string,Sex string,Sage int,Sdept string)row format delimited fields terminated by ','stored as textfile; create table course(Cno int,Cname string) row format delimited fields terminated by ',' stored as textfile; create table sc(Sno int,Cno int,Grade int)row format delimited fields terminated by ',' stored as textfile; load data local inpath '/home/hadoop/hivedata/students.txt' overwrite into table student; load data local inpath '/home/hadoop/hivedata/sc.txt'

HQL with a collection in the WHERE clause

こ雲淡風輕ζ 提交于 2020-01-12 14:31:15
问题 I've been trying for the this whole a query who is officially giving me nightmares. The system is a user and contact management. So I have UserAccount , Contact and Phone . UserAccount has a bidirectional one-to-many relationship with Contact and an unidirectional one on phone all mapped by a Set : //UserAccount mapping @OneToMany(targetEntity=PhoneImpl.class, cascade= {CascadeType.ALL}) @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private Set

Hibernate AliasToBean with Collection

笑着哭i 提交于 2020-01-12 10:07:09
问题 I have a bi-directional one-to-many relationship defined between Parent and Child classes. I'm looking to execute a query such that I can return a single parent, and a subset of its children in a bean. public class Parent { private int id; private Set<Child> children = new HashSet<Child>(0); // other fields + getters and setters } public class Child { private Parent parent; private int age; // other fields + getters and setters } The output I'm looking to achieve is: public class