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约束 嵌 ...
随机推荐
- py库: pymysql、 json (mysql数据库)
数据库查询结果,用json返回: #连接数据库 import pymysql print(pymysql.VERSION) conn = pymysql.Connect(host='localhost ...
- mybatis一(常用配置信息和获取插入后id)
<!--配置文件--><?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE conf ...
- scrapy中deferred的回调
def _next_request_from_scheduler(self, spider):#在引擎中处理一个请求 slot = self.slot request = slot.scheduler ...
- linux 下使用 curl post
命令: curl -X POST -d @/etc/lazada/lazada_tracking.txt http://localhost:8080/booking/rs/LazadaServic ...
- leetcode1021
class Solution(object): def removeOuterParentheses(self, S: str) -> str: li = list() bcode = 0 te ...
- leetcode1017
这道题目很巧妙,似乎是有些过于巧妙了,属于我未知领域的类型,把原作者的解决方案放这里.(看大家都在给差评,我也顺手给个差评吧--) 参考:https://leetcode.com/problems/c ...
- php实现单点登录实例
1.准备两个虚拟域名 127.0.0.1 www.a.com127.0.0.1 www.b.com 2.在a的根目录下创建以下文件 1 //index.php 2 3 <?php 4 sessi ...
- RESTFUL 设计风格
RESTFUL 规范总结: Rest是web服务的一种架构风格;使用HTTP,URI,XML,JSON,HTML等广泛流行的标准和协议;轻量级,跨平台,跨语言的架构设计;它是一种设计风格,不是一种标 ...
- C++复习:类和对象
类和对象 基本概念 1)类.对象.成员变量.成员函数 2)面向对象三大概念 封装.继承.多态 3)编程实践 类的定义和对象的定义,对象的使用 求圆形的面积 定义Teacher类 ...
- 【转】JS windows.open()详解
window.open(url, name, features, replace) Arguments - 参数 url 可选字符串参数,指向要在新窗口中显示的文档的URL.如果省略该参数,或者参 ...