hql

【HQL】函数汇总

匿名 (未验证) 提交于 2019-12-02 23:51:01
背景 SQL几乎是初级分析师80%的工作内容,当然在我的规划里,中级分析师已经要做好维度建模工作以及最好有OLAP系统工具啥的,或者已经能主动分析写文章了,尽量减少SQL的无效使用。这是我自己的定位,其他人无所谓。 anyway,SQL对分析师来说是一项很棒的工具,HQL即Hive SQL,相对MySQL 函数更多更复杂一些。 另外,在查询能使用哪个函数时,通常有三种情况: 一是记得某个函数名,但忘了参数怎么用,索引是函数名; 二是想要实现某个目的,不太清楚有什么函数能实现,索引是函数的作用; 三是想实现某个较为复杂的目的,不太清楚组合哪些函数能实现,这里通常涉及多个函数,索引是使用案例。 所以在后续文章中,前三列会体现这个问题。 数仓同步表 与MySQL这种事务性数据库不同的是,数据仓库是一个面向主题的(Subject Oriented)、集成的(Integrate)、相对稳定的(Non-Volatile)、反映历史变化(Time Variant)的数据集合,用于支持管理决策。前三个性质且不说,最后一个反映历史变化的是如何体现的呢?这在于同步线上事务表的方式。 线上表同步下来有三种方式,增量表、全量表、拉链表。 另外提一下,数仓都是在凌晨两三点T+1同步;除了字段外,数仓还有个分区的概念,用于快速取某一块的数据,通常日期dt会作为分区,其他例如业务类型啥的也可以作为分区

Hibernate学习笔记三(HQL查询)

匿名 (未验证) 提交于 2019-12-02 23:34:01
HQL语句 在Hibernate中,虽然简单的主键查询语句我们可以直接使用API让Hibernate帮我们生成,但是复杂的查询语句就需要我们自己手写,Hibernate就提供了一种HQL语句给我们使用,HQL是Hibernate Query Language的缩写,HQL是一种比较接近SQL的语句,只不过我们查询的对象不再是数据库的表,而是持久化类。 全查语句 /** * 全查操作 */ @Test public void test1() { //通过自定义工具类获取session,详情见笔记一 Session session = HibernateUtil.openSession(); //开启事务 Transaction transaction = session.beginTransaction(); /** * 创建查询语句 * 全查意思是将表中所有数据都查出来 * 使用的HQL语句是“from 类名”,这里的User是持久化类的类名,注意不是表名 * 不能使用select * */ Query query = session.createQuery("from User"); /** * 获取所有数据,返回的是list集合,集合放的是持久化类的对象 */ List<User> list = query.list(); /** * 遍历打印每一条数据 */ for

How to pass parameter to @Query annotation with hql

百般思念 提交于 2019-12-02 22:33:42
问题 Here is my hql requete : @Query("select a from Agent where a.visibility = true a order by a.id desc") public Page<Agent> getAllAgents(Pageable pageable); I want to select all agents that have visibility true. In my Agent class a have Boolean visibility attribute with getVisibility and setVisibility functions. In my data base "visibility" stored as bit(1). I tried a.visibility = 1, ... = '1', ...= 'TRUE', ...='true', ... is true. But i get this error : Caused by: org.hibernate.hql.internal.ast

easyui

匿名 (未验证) 提交于 2019-12-02 21:53:52
最近在学习easyui的使用,在学到datagrid的时候遇到了一些问题,终于抽点时间整理了一下,分享出来,请各位前辈高手多多指教! 2、easyui的datagrid的使用方法 在这里,datagrid的使用我不做过多讲解,俺毕竟是初学者,不敢班门弄斧。所以就简单带一下。 ①、在easyui的layout中的center中定义一个table,id为“datagridTable”。 <div region="center" border="false"> <table id="datagridTable"></table> </div> ②、使用javascript的方式让这个table变为一个easyui的datagrid。当然也可以给这个table指定class属性为“easyui-datagrid”,两种方式都可以,萝卜白菜,各有所爱。由于datagrid和后台的数据交互打交道的比较多,所以俺使用的功能比较好控制的javascript方式定义。 代码如下,其中具体的属性和方法请查看easyui文档,官网地址: http://www.jeasyui.com/documentation/datagrid.php <script type="text/javascript"> $(function() { $("#datagridTable").datagrid({ url :

java之SQL语句

匿名 (未验证) 提交于 2019-12-02 21:35:04
批量更新 //查询User表中的所有记录 IGNORE ) FORWARD_ONLY ); int count = 0; while (uScrollableResults.next()) { uScrollableResults .get(0) ; setName ("newName"); if ( ++ count % 20 ) { DML风格的批量更新 String hqlUpdate = "update User u set name= :newName"; int updateEntities = session.createQuery(hqlUpdate) setString ( "newName" , " 新名字 " ) String halDelete = "delete User"; int deleteEntities = session.createQuery(halDelete) 1HQL查询 HQL是 Hibernate Query Language的缩写,HQL的语法很像SQL的语法,但HQL是一种面向 的查询语言。SQL的操作对象是数据表、列等数据库对象,而HQL的操作对象是类、实例、属性等。 HQL是完全面向对象的查询语言,因此可以支持继承、多态等特性。 HQL查询依赖于 Query类,每个Quey实例对应一个查询对象。使用HL查询按如下步骤进 获取

Hibernate queries slow down drastically after an entity is loaded in the session

隐身守侯 提交于 2019-12-02 21:00:57
I'm using Hibernate EntityManager, and am experiencing a weird slowdown in my Hibernate queries. Take a look at this code: public void testQuerySpeed() { for(int i = 0; i < 1000; i++) { em.createNativeQuery("SELECT 1").getResultList(); } } This runs in about 750ms on my machine. Not blazing fast considering it's just selecting a constant integer, but acceptable. My problem arises the moment ANY entities are loaded in my EntityManager session before I launch my query: public void testQuerySpeed() { CommercialContact contact = em.find(CommercialContact.class, 1890871l); for(int i = 0; i < 1000;

How to get last record from Mysql using Hibernate?

独自空忆成欢 提交于 2019-12-02 20:55:31
List<Lahetys> last = session.createQuery("from lahetys order by lahetysNro DESC LIMIT 1").list(); and in the log I got: INFO: Hibernate: select from order by lahetysNro DESC LIMIT 1 WARN: SQL Error: 1064, SQLState: 42000 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from order by lahetysNro DESC LIMIT 1' at line 1 What has happend to "from LAHETYS"? What is the best practice to handle that with HQL or/and with SQL? Another problem: Lahetys last = (Lahetys)session.createSQLQuery("select * from

Hibernate Dynamic Order

纵饮孤独 提交于 2019-12-02 20:17:39
问题 Hi i want to sort in HQL ORDER BY IF g.groupAdminId=:adminid THEN 1 ELSE 0 END ASC But it doesn't work, i want to have all entities where the user is admin first, how can i archieve this? 回答1: I don't believe it is possible to put named parameters outside a where clause. It is possible to order according to expressions: from User U order by case when U.group.name = 'Admin' then 0 when U.group.name = 'Superuser' then 1 else 2 end asc More on case in HQL docs : For your particular problem

JPA/Hibernate: Escaping HQL keywords

江枫思渺然 提交于 2019-12-02 19:17:00
问题 This is similar to How to escape reserved words in Hibernate's HQL. But I use JPA, so the solution isn't applicable. So, how can I escape HQL keywords in JPA? Example query: ( count is the offending.) em.createQuery("INSERT INTO Count (id, count) SELECT 1, ?").setParameter(1, id).executeUpdate(); There's this jira HHH-3811, still open. Not sure if relevant since it's about SQL keywords, not HQL keywords. 回答1: You could try something like this: em.createQuery("INSERT INTO Count c (c.id, c

[Ljava.lang.Object; cannot be cast to

安稳与你 提交于 2019-12-02 19:06:37
I want to get value from the database, in my case I use List to get the value from the database but I got this error Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to id.co.bni.switcherservice.model.SwitcherServiceSource at id.co.bni.switcherservice.controller.SwitcherServiceController.LoadData(SwitcherServiceController.java:48) at id.co.bni.switcherservice.controller.SwitcherServiceController.main(SwitcherServiceController.java:62) this is my code Query LoadSource = session_source.createQuery("select CLIENT,SERVICE,SERVICE_TYPE,PROVIDER_CODE,COUNT(