hql

HQL之多表查询(一对多和多对多)

点点圈 提交于 2020-01-23 00:34:43
一、一对多 以班级Classes和学生Student为例: 回忆sql语句: //内链接,两种方式效果一样,查询的是两边都有的数据 SELECT c.*,s.* FROM classes c,student s WHERE s.cid=c.cid; SELECT c.cname,s.sname FROM classes c INNER JOIN student s ON s.cid=c.cid; //左外连接,在内链接基础上,左边表有而右边表没有,两种方式等效; SELECT c.* ,s.* FROM student s LEFT OUTER JOIN classes c ON s.cid=c.cid; SELECT c.* ,s.* FROM student s LEFT JOIN classes c ON s.cid=c.cid; //右外连接,在内链接基础上,右边有而左边无,两种方式等效; SELECT c.* ,s.* FROM classes c RIGHT OUTER JOIN student s ON s.cid=c.cid; SELECT c.* ,s.* FROM classes c RIGHT JOIN student s ON s.cid=c.cid; HQL语句: //查询所有: from Classes c,Student s where c.cid=s

What's the best way to write if/else if/else if/else in HIVE?

假如想象 提交于 2020-01-20 04:32:05
问题 Hive uses IF(condition, expression, expression), so when I want to do if / else if / else if / else, I have to do: IF(a, 1, IF(b, 2, IF(c, 3, 4))) Is there a better way to do this that's more readable? Looking for something similar to the standard if (a) { 1 } else if (b) { 2 } else if (c) { 3 } else { 4 } 回答1: You can use Hive Conditional CASE WHEN function for if-else scenario. The CASE Statement will provide you better readability with the same functionality. CASE WHEN (condition1) THEN

DAO层使用泛型的两种方式

梦想与她 提交于 2020-01-19 09:54:50
1.DAO层使用泛型类,主要是定义一些通用的增删改查,然后其他DAO的类都来继承该类,通过构造方法将class对象传给该泛型类 定义泛型接口 package sanitation.dao;import java.util.List;/** * * @param <T> */public interface GenericDAO <T>{ /** * 通过ID获得实体对象 * * @param id实体对象的标识符 * @return 该主键值对应的实体对象 */ T findById(int id); /** * 将实体对象持久化 * * @param entity 需要进行持久化操作的实体对象 * @return 持久化的实体对象 */ T makePersitent(T entity); /** * 将实体变为瞬态 * * @param entity需要转变为瞬态的实体对象 */ void makeTransient(T entity); /** * 将一系列的实体变为瞬态,使用本地sql * * @param hql */ void makeTransientByIds(String sql); /** * * 使用hql语句进行分页操作 * * @param hql * @param offset 第一条记录索引 * @param pageSize 每页需要显示的记录数 *

java web项目DAO层通用接口BaseDao与实现类BaseDaoImpl

喜你入骨 提交于 2020-01-19 09:19:23
在 spring + hibernate 的web项目中,处理数据层通常会使用Spring框架提供的HibernateTemplate类提供的方法。通常的用法是每一个实体类对应的去写DAO层的接口和实现类。每个实现类中都写hibernateTemp.save(entity)、hibernateTemp.update(entity)、hibernateTemp.get(id)...这样写固然没错,但存在着大量的重复代码。所以懒惰的程序员烦了,他们要写一个通用的实现类来解决这个问题,让DAO层解放出来。如果有特殊的需要则在实现类中写个方法去处理,没有特殊的需要那么我们就不用在写DAO层的代码了。 下面是我写的一个通用DAO层接口和实现类,初次写这种通用型的代码可能会有很多不到位的地方,如果您看到了,请在评论中不吝赐教,谢谢! BaseDao. Java package org.lxl.mr.common.base.db; import java.util.List; /** * 通用数据层接口 * @author liuXueLiang * @param <Entity> * @param <PK> */ public interface BaseDao<Entity,PK> { /** * 增加 * @param entity */ public void save(Entity

Ignore a FetchType.EAGER in a relationship

寵の児 提交于 2020-01-19 04:48:31
问题 I have a problem with EAGERs relationships in a big application. Some entities in this application have EAGER associations with other entities. This become "poison" in some functionalities. Now my team needs to optimize this functionalities, but we cannot change the fetch type to LAZY , because we would need to refactor the whole application. So, my question: Is there a way to do a specific query ignoring the EAGERs associations in my returned entity? Example: when a I have this entity Person

Ignore a FetchType.EAGER in a relationship

旧街凉风 提交于 2020-01-19 04:47:27
问题 I have a problem with EAGERs relationships in a big application. Some entities in this application have EAGER associations with other entities. This become "poison" in some functionalities. Now my team needs to optimize this functionalities, but we cannot change the fetch type to LAZY , because we would need to refactor the whole application. So, my question: Is there a way to do a specific query ignoring the EAGERs associations in my returned entity? Example: when a I have this entity Person

Retrieving rows based on a certain criteria regarding a many-to-many mapping in Hibernate

这一生的挚爱 提交于 2020-01-16 08:11:10
问题 I'm just copy & pasting some of the introductory text from one of my questions, since the same table relationship is involved in this question also. I have three of many tables in Oracle (10g) database as listed below. I'm using Hibernate Tools 3.2.1.GA with Spring version 3.0.2. Product - parent table Colour - parent table ProductColour - join table - references colourId and prodId of Colour and Product tables respectively Where the table ProductColour is a join table between Product and

hive实战

随声附和 提交于 2020-01-16 05:05:05
hive实战 - qiang.xu - 博客园 hive实战 1. 安装hive 2. hive实战 3. hive存储模型 4. 深入hql查询语言 5. 参考资料及代码下载 <1>. 安装hive 下载hive,下载地址 http://mirror.bjtu.edu.cn/apache//hive/ ,解压该文件: xuqiang@ubuntu:~/hadoop/src/hive$ tar zxvf hive-0.7.0-bin.tar.gz 设置环境变量: xuqiang@ubuntu:~/hadoop/src/hive$ cd hive-0.7.0-bin/ xuqiang@ubuntu:~/hadoop/src/hive/hive-0.7.0-bin$ export HIVE_HOME=`pwd` 添加HIVE_HOME到环境变量PATH中: xuqiang@ubuntu:~/hadoop/src/hive$ export PATH=$HIVE_HOME/bin:$PATH; 在运行hive之前,请确保变量HADOOP_HOME已经设置,如果没有设置,可以使用export命令设置该变量。 然后需要在hdfs上创建如下的目录来保存hive相关的数据。 xuqiang@ubuntu:~ / hadoop / src / hive $ $ HADOOP_HOME / bin /

How to view the calculated value of a hive variable

随声附和 提交于 2020-01-14 16:44:32
问题 I'm trying to see the value of a calculated value in hive. For example, I'm trying to get the year from this tablename: set TABLE_NAME = orders2014; set TABLE_YEAR = substr(${hiveconf:TABLE_NAME},6,4); set TABLE_YEAR; The result I get is the uncalculated string; substr(${hiveconf:TABLE_NAME},6,4) What I would like to get is the calculated value, "2014". How would I see this value? Thanks 回答1: Hive "variables" are actually nothing more than a text replacement mechanism. The replacement is done

NHibernate GroupBy and Sum

人盡茶涼 提交于 2020-01-14 14:48:07
问题 I am starting a study on NHibernate, and I have a problem I'm not able to solve, I wonder if someone could help me. The mapping is working "correctly" but when I try to do the grouping and the sum, the application returns the following error: "could not resolve property: Course.Price of: Persistence.POCO.RequestDetail" var criteria = session.CreateCriteria(typeof(RequestDetail)) .SetProjection( Projections.ProjectionList() .Add(Projections.RowCount(), "RowCount") .Add(Projections.Sum("Course