hibernate mysql视图操作
hibernate对视图操作,首先建立数据库视图
视图v_invite:
create
view pintu.v_invite as
select
cp.user_id as be_user_id,
cai.activity_invite_id,
cai.person_id,
cai.person_name,
cai.be_person_id,
cai.activity_id,
cai.invite_time
from
ptcom.com_person cp,
ptcom.com_activity_invite cai
where
cp.person_id = cai.be_person_id
生成hibernate视图mapping映射
<hibernate-mapping>
<class name="com.test.pojo.entity.VComActivityInvite" table="v_com_activity_invite" catalog="pintu">
<composite-id name="id" class="com.test.pojo.entity.VComActivityInviteId">
<key-property name="beUserId" type="java.lang.String">
<column name="be_user_id" length="32" />
</key-property>
<key-property name="activityInviteId" type="java.lang.Long">
<column name="activity_invite_id" />
</key-property>
<key-property name="personId" type="java.lang.Long">
<column name="person_id" />
</key-property>
<key-property name="personName" type="java.lang.String">
<column name="person_name" length="45" />
</key-property>
<key-property name="bePersonId" type="java.lang.Long">
<column name="be_person_id" />
</key-property>
<key-property name="activityId" type="java.lang.Long">
<column name="activity_id" />
</key-property>
<key-property name="inviteTime" type="java.util.Date">
<column name="invite_time" length="19" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
对性实体POJO:VComActivityInvite
public class VComActivityInvite implements java.io.Serializable {
// Fields
private VComActivityInviteId id;
// Constructors
public VComActivityInvite() {
}
public VComActivityInvite(VComActivityInviteId id) {
this.id = id;
}
// Property accessors
public VComActivityInviteId getId() {
return this.id;
}
public void setId(VComActivityInviteId id) {
this.id = id;
}
}
对应视图数据体:VComActivityInviteId
public class VComActivityInviteId implements java.io.Serializable {
// Fields
private String beUserId;
private Long activityInviteId;
private Long personId;
private String personName;
private Long bePersonId;
private Long activityId;
private Date inviteTime;
// Constructors
public VComActivityInviteId() {
}
public VComActivityInviteId(Long activityInviteId) {
this.activityInviteId = activityInviteId;
}
public VComActivityInviteId(String beUserId, Long activityInviteId,
Long personId, String personName, Long bePersonId, Long activityId,
Date inviteTime) {
this.beUserId = beUserId;
this.activityInviteId = activityInviteId;
this.personId = personId;
this.personName = personName;
this.bePersonId = bePersonId;
this.activityId = activityId;
this.inviteTime = inviteTime;
}
// Property accessors
public String getBeUserId() {
return this.beUserId;
}
public void setBeUserId(String beUserId) {
this.beUserId = beUserId;
}
public Long getActivityInviteId() {
return this.activityInviteId;
}
public void setActivityInviteId(Long activityInviteId) {
this.activityInviteId = activityInviteId;
}
public Long getPersonId() {
return this.personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public String getPersonName() {
return this.personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
public Long getBePersonId() {
return this.bePersonId;
}
public void setBePersonId(Long bePersonId) {
this.bePersonId = bePersonId;
}
public Long getActivityId() {
return this.activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
public Date getInviteTime() {
return this.inviteTime;
}
public void setInviteTime(Date inviteTime) {
this.inviteTime = inviteTime;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof VComActivityInviteId))
return false;
VComActivityInviteId castOther = (VComActivityInviteId) other;
return ((this.getBeUserId() == castOther.getBeUserId()) || (this
.getBeUserId() != null
&& castOther.getBeUserId() != null && this.getBeUserId()
.equals(castOther.getBeUserId())))
&& ((this.getActivityInviteId() == castOther
.getActivityInviteId()) || (this.getActivityInviteId() != null
&& castOther.getActivityInviteId() != null && this
.getActivityInviteId().equals(
castOther.getActivityInviteId())))
&& ((this.getPersonId() == castOther.getPersonId()) || (this
.getPersonId() != null
&& castOther.getPersonId() != null && this
.getPersonId().equals(castOther.getPersonId())))
&& ((this.getPersonName() == castOther.getPersonName()) || (this
.getPersonName() != null
&& castOther.getPersonName() != null && this
.getPersonName().equals(castOther.getPersonName())))
&& ((this.getBePersonId() == castOther.getBePersonId()) || (this
.getBePersonId() != null
&& castOther.getBePersonId() != null && this
.getBePersonId().equals(castOther.getBePersonId())))
&& ((this.getActivityId() == castOther.getActivityId()) || (this
.getActivityId() != null
&& castOther.getActivityId() != null && this
.getActivityId().equals(castOther.getActivityId())))
&& ((this.getInviteTime() == castOther.getInviteTime()) || (this
.getInviteTime() != null
&& castOther.getInviteTime() != null && this
.getInviteTime().equals(castOther.getInviteTime())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getBeUserId() == null ? 0 : this.getBeUserId().hashCode());
result = 37
* result
+ (getActivityInviteId() == null ? 0 : this
.getActivityInviteId().hashCode());
result = 37 * result
+ (getPersonId() == null ? 0 : this.getPersonId().hashCode());
result = 37
* result
+ (getPersonName() == null ? 0 : this.getPersonName()
.hashCode());
result = 37
* result
+ (getBePersonId() == null ? 0 : this.getBePersonId()
.hashCode());
result = 37
* result
+ (getActivityId() == null ? 0 : this.getActivityId()
.hashCode());
result = 37
* result
+ (getInviteTime() == null ? 0 : this.getInviteTime()
.hashCode());
return result;
}
}
在操作中,对视图进行查询,引入查询条件:
String hql = "select count(*) from VComActivityInvite vca where vca.id.beUserId = '" + userId+"'";
return ((Number)vComActivityInviteDao.createQuery(hql).uniqueResult()).intValue();
父类 id 对应 <composite-id name="id" class="com.test.pojo.entity.VComActivityInviteId">
hibernate3.2对应统计数量返回LONG型,需转化如下
((Number)vComActivityInviteDao.createQuery(hql).uniqueResult()).intValue
hibernate mysql视图操作的更多相关文章
- MySQL 视图的基础操作(五)
1.为什么使用视图: 为了提高复杂SQL语句的复用性和表操作的安全性(例如:工资字段不想展示给所有能查看该查询结果的人),MySQL提供了视图特性.所谓视图,本质上是一种虚拟表,其内容与真实的 ...
- MySQL学习——操作视图
MySQL学习——操作视图 摘要:本文主要学习了使用DDL语句操作视图的方法. 了解视图 是什么 视图是从一个.多个表或者视图中导出的表,包含一系列带有名称的数据列和若干条数据行. 特点 视图不是数据 ...
- mysql视图的操作
一.创建视图的语法形式 CREATE VIEW view_name AS 查询语句 ; 使用视图 SELECT * FROM view_name ; 二.创建各种视图 1.封装实现查询常量语句的视图, ...
- Mysql 视图 游标 触发器 存储过程 事务
Mysql 视图 触发器 存储过程 游标 游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用fetch语句可以移动该指针,从而对游标中 ...
- mysql 视图(view)
什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...
- Mysql视图的作用及其性能分析
定义:视图是从一个或几个基本表导出的表,它与基本表不同,是一个虚表. 作用: 1.简化操作,不用进行多表查询. 2.当不同种类的用用户共享同一个数据库时,非常灵活,(用户以不同的 方式看待同一数据. ...
- MYSQL 基础操作
1.MySQL基础操作 一:MySQL基础操作 1:MySQL表复制 复制表结构 + 复制表数据 create table t3 like t1; --创建一个和t1一样的表,用like(表结构也一样 ...
- MYSQL视图的学习笔记
MYSQL视图的学习笔记,学至Tarena金牌讲师,金色晨曦科技公司技术总监沙利穆 课程笔记的综合. 视图及图形化工具 1. 视图的定义 视图就是从一个或多个表中,导出来的表,是一个虚 ...
- 深入解析MySQL视图view
阅读目录---深入解析MySQL视图view 创建视图 查看视图 视图的更改 create or replace view alter DML drop 使用with check option约束 嵌 ...
随机推荐
- python二进制转换
例一.题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 分析: python没有unsigned int类型 >>> print ("%x&qu ...
- JAVA 中文 unicode 相互转换 文件读取
package com.test; import org.junit.Test; public class JunitTest { @Test public void test(){ String p ...
- 高程三 BOM 读书笔记
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Feign 的简单使用(2)
依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>sp ...
- 【Noip模拟 20161005】公约数
问题描述 小ww最近仔细研究了公约数,他想到了以下问题:现有nn个正整数,从中选k(2≤k≤n)k(2≤k≤n) 个,设这kk个数的最大公约数为gg,则这kk个数的价值为k×gk×g.求这个价值的最大 ...
- Delphi 中的颜色常量及效果图
颜色名称 颜色效果 Hex HTML clBlack $000000 #000000 clMaroon $000080 #800000 clGreen $008000 #00800 ...
- UNITY2018.3 在editor下运行时new memoryprofiler显示 shader占用内存很大的问题在安卓上并没有看到
在安卓机上完全看不到shader占用的内存,但问题是,shader在安卓上真的几乎不占用内存了?(我们的游戏中只使用了mobile下的shader) 参考下面这个文章,说是真机上也有: Unity3D ...
- PRC远程过程调用
RPC(Remote Promote Call) 一种进程间通信方式.允许像调用本地服务一样调用远程服务. RPC框架的主要目标就是让远程服务调用更简单.透明.RPC框架负责屏蔽底层的传输方式(TCP ...
- 切换用户身份su与sudo
普通用户切换到root用户的方式有:su和sudo. 1,su - (su为switch user,即切换用户的简写) 格式:su -l USERNAME(-l为login,即登陆的简写) -l可以将 ...
- Haskell语言学习笔记(75)Conduit
安装 conduit $ cabal install conduit Installed conduit-1.3.0.3 Prelude> import Conduit Prelude Cond ...