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约束 嵌 ...
随机推荐
- 查看mysql 表大小
select round(sum(DATA_LENGTH / 1024 / 1024 ), 2) from `information_schema`.`tables` where table_sche ...
- MFC相关函数汇总(持续汇总跟新中)
最近有一项关于MFC的任务,做完后总结了一些使用的函数,希望对大家有帮助,也是怕自己忘了所以就写了这篇博客,方便后续的工作. 1,FindWindow() 获得窗口句柄: 2,GetWindowRec ...
- 如何在notepad++实现代码自动化排版(调用Astyle)
我先介绍这个怎么在notepad++中调用原版的astyle的方法. 在notepad++:运行或是F5, 在输入框中选择astyle.exe所在的目录,什么你没有astyle,下载地址https:/ ...
- MySql Delete不走索引问题
如果delete语句带有查询,写法不对会导致不走索引. 简单粗暴的办法:拆两条sql,一条查询,一条delete ======================= [不走索引的写法] DELETE FR ...
- 小柒2012 / spring-boot-quartz
spring-boot-quartz 基于spring-boot+quartz的CRUD动态任务管理系统,适用于中小项目. 基于spring-boot 2.x +quartz 的CRUD任务管理系统: ...
- VB-串口通信详解
转载:https://blog.csdn.net/dongyue786/article/details/8177047 MSComm 控件通过串行端口传输和接收数据,为应用程序提供串行通讯功能.MSC ...
- jquery下的正反选操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- How to Pronounce the Days of the Week
How to Pronounce the Days of the Week Share Tweet Share Vocabulary study: how to pronounce the days ...
- Haskell语言学习笔记(85)Async
安装 async $ cabal install async async-2.2.1 installed async / wait / concurrently async :: IO a -> ...
- 使用arguments对象验证函数的参数是否合法
<script>function sum(arg1,arg2) //加法函数{ var realArgCount = arguments.length; //调用函数时传递的实参个数 va ...