Java bean:

package com.my.bean;

import java.util.Date;

public class WorkPack {

    private String uWorkPackID;
private String BaselineID;
private String SourceID;
private String uProjectID;
private String sPackName;
private String sDescription;
private Date dPackStartDate;
private Date dPackEndDate;
private short iStatus;
private String uParentID;
private java.math.BigDecimal fPMPlanWorkload;
private short iPriority;
private String sBizID;
private String sDeadwayMemo;
private short IsIteration;
private short ProgressRate;
private String Owner;
private short ScheduleStatus;
private String sCreator;
private Date dCreateTime;
private String sModifiedUser;
private Date sModifiedTime;
private String remark;
private String KeyIn;
private String KeyOut;
private java.math.BigDecimal WorkLineBase;
private String UpdateType;
private String Predecessors; public String getuWorkPackID() {
return uWorkPackID;
}
public void setuWorkPackID(String uWorkPackID) {
this.uWorkPackID = uWorkPackID;
}
public String getBaselineID() {
return BaselineID;
}
public void setBaselineID(String baselineID) {
BaselineID = baselineID;
}
public String getSourceID() {
return SourceID;
}
public void setSourceID(String sourceID) {
SourceID = sourceID;
}
public String getuProjectID() {
return uProjectID;
}
public void setuProjectID(String uProjectID) {
this.uProjectID = uProjectID;
}
public String getsPackName() {
return sPackName;
}
public void setsPackName(String sPackName) {
this.sPackName = sPackName;
}
public String getsDescription() {
return sDescription;
}
public void setsDescription(String sDescription) {
this.sDescription = sDescription;
}
public Date getdPackStartDate() {
return dPackStartDate;
}
public void setdPackStartDate(Date dPackStartDate) {
this.dPackStartDate = dPackStartDate;
}
public Date getdPackEndDate() {
return dPackEndDate;
}
public void setdPackEndDate(Date dPackEndDate) {
this.dPackEndDate = dPackEndDate;
}
public short getiStatus() {
return iStatus;
}
public void setiStatus(short iStatus) {
this.iStatus = iStatus;
}
public String getuParentID() {
return uParentID;
}
public void setuParentID(String uParentID) {
this.uParentID = uParentID;
}
public java.math.BigDecimal getfPMPlanWorkload() {
return fPMPlanWorkload;
}
public void setfPMPlanWorkload(java.math.BigDecimal fPMPlanWorkload) {
this.fPMPlanWorkload = fPMPlanWorkload;
}
public short getiPriority() {
return iPriority;
}
public void setiPriority(short iPriority) {
this.iPriority = iPriority;
}
public String getsBizID() {
return sBizID;
}
public void setsBizID(String sBizID) {
this.sBizID = sBizID;
}
public String getsDeadwayMemo() {
return sDeadwayMemo;
}
public void setsDeadwayMemo(String sDeadwayMemo) {
this.sDeadwayMemo = sDeadwayMemo;
}
public short getIsIteration() {
return IsIteration;
}
public void setIsIteration(short isIteration) {
IsIteration = isIteration;
}
public short getProgressRate() {
return ProgressRate;
}
public void setProgressRate(short progressRate) {
ProgressRate = progressRate;
}
public String getOwner() {
return Owner;
}
public void setOwner(String owner) {
Owner = owner;
}
public short getScheduleStatus() {
return ScheduleStatus;
}
public void setScheduleStatus(short scheduleStatus) {
ScheduleStatus = scheduleStatus;
}
public String getsCreator() {
return sCreator;
}
public void setsCreator(String sCreator) {
this.sCreator = sCreator;
}
public Date getdCreateTime() {
return dCreateTime;
}
public void setdCreateTime(Date dCreateTime) {
this.dCreateTime = dCreateTime;
}
public String getsModifiedUser() {
return sModifiedUser;
}
public void setsModifiedUser(String sModifiedUser) {
this.sModifiedUser = sModifiedUser;
}
public Date getsModifiedTime() {
return sModifiedTime;
}
public void setsModifiedTime(Date sModifiedTime) {
this.sModifiedTime = sModifiedTime;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getKeyIn() {
return KeyIn;
}
public void setKeyIn(String keyIn) {
KeyIn = keyIn;
}
public String getKeyOut() {
return KeyOut;
}
public void setKeyOut(String keyOut) {
KeyOut = keyOut;
}
public java.math.BigDecimal getWorkLineBase() {
return WorkLineBase;
}
public void setWorkLineBase(java.math.BigDecimal workLineBase) {
WorkLineBase = workLineBase;
}
public String getUpdateType() {
return UpdateType;
}
public void setUpdateType(String updateType) {
UpdateType = updateType;
}
public String getPredecessors() {
return Predecessors;
}
public void setPredecessors(String predecessors) {
Predecessors = predecessors;
} }

Hibernate的mapping xml:

<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.my.bean.WorkPack" table="PPM_WorkPack">
<id name="uWorkPackID" type="java.lang.String" length="37">
<column name="uWorkPackID" />
<generator class="assigned" />
</id>
<property name="BaselineID" type="java.lang.String" length="37">
<column name="BaselineID" />
</property>
<property name="SourceID" type="java.lang.String" length="37">
<column name="SourceID" />
</property>
<property name="uProjectID" type="java.lang.String" length="37">
<column name="uProjectID" />
</property>
<property name="sPackName" type="java.lang.String" length="200">
<column name="sPackName" />
</property>
<property name="sDescription" type="java.lang.String" length="4000">
<column name="sDescription" />
</property>
<property name="dPackStartDate" type="java.util.Date">
<column name="dPackStartDate" />
</property>
<property name="dPackEndDate" type="java.util.Date">
<column name="dPackEndDate" />
</property>
<property name="iStatus" type="short">
<column name="iStatus" />
</property>
<property name="uParentID" type="java.lang.String" length="37">
<column name="uParentID" />
</property>
<property name="fPMPlanWorkload" type="java.math.BigDecimal">
<column name="fPMPlanWorkload" />
</property>
<property name="iPriority" type="short">
<column name="iPriority" />
</property>
<property name="sBizID" type="java.lang.String" length="60">
<column name="sBizID" />
</property>
<property name="sDeadwayMemo" type="java.lang.String" length="4000">
<column name="sDeadwayMemo" />
</property>
<property name="IsIteration" type="short">
<column name="IsIteration" />
</property>
<property name="ProgressRate" type="short">
<column name="ProgressRate" />
</property>
<property name="Owner" type="java.lang.String" length="255">
<column name="Owner" />
</property>
<property name="ScheduleStatus" type="short">
<column name="ScheduleStatus" />
</property>
<property name="sCreator" type="java.lang.String" length="255">
<column name="sCreator" />
</property>
<property name="dCreateTime" type="java.util.Date">
<column name="dCreateTime" />
</property>
<property name="sModifiedUser" type="java.lang.String" length="255">
<column name="sModifiedUser" />
</property>
<property name="sModifiedTime" type="java.util.Date">
<column name="sModifiedTime" />
</property>
<property name="remark" type="java.lang.String" length="4000">
<column name="remark" />
</property>
<property name="KeyIn" type="java.lang.String" length="100">
<column name="KeyIn" />
</property>
<property name="KeyOut" type="java.lang.String" length="100">
<column name="KeyOut" />
</property>
<property name="WorkLineBase" type="java.math.BigDecimal">
<column name="WorkLineBase" />
</property>
<property name="UpdateType" type="java.lang.String" length="25">
<column name="UpdateType" />
</property>
<property name="Predecessors" type="java.lang.String" length="800">
<column name="Predecessors" />
</property>
</class> </hibernate-mapping>

测试例子:

package com.my.test;

import java.util.Date;
import java.util.List;
import java.util.UUID; import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import com.my.bean.WorkPack; public class TestHibernate { @SuppressWarnings("unchecked")
public static void main(String[] args) {
Configuration cfg = new Configuration();
@SuppressWarnings("deprecation")
SessionFactory factory = cfg.configure().buildSessionFactory();
Session session = factory.openSession();
org.hibernate.Transaction trans = session.beginTransaction(); //-------------------------------------------------------------
// Select
//-------------------------------------------------------------
String hqlSelect = "from WorkPack where uProjectID=:uProjectID";
Query querySelect = session.createQuery(hqlSelect);
querySelect.setParameter("uProjectID", "b84570f4-81de-4b18-abb3-48c431e398c4");
List<WorkPack> list = querySelect.list(); //-------------------------------------------------------------
// Update
//-------------------------------------------------------------
String hqlUpdate = "update WorkPack set sPackName=:sPackName where uWorkPackID=:uWorkPackID";
Query queryUpdate = session.createQuery(hqlUpdate);
queryUpdate.setParameter("sPackName", "hi");
queryUpdate.setParameter("uWorkPackID", "A1514770-2D6F-43A5-AF83-DD26068F0DF9");
int resultUpdate = queryUpdate.executeUpdate(); //-------------------------------------------------------------
// Insert
//-------------------------------------------------------------
WorkPack wp = new WorkPack();
wp.setuWorkPackID(UUID.randomUUID().toString());
wp.setBaselineID("00000000-0000-0000-0000-000000000001");
wp.setSourceID(null);
wp.setuProjectID("B84570F4-81DE-4B18-ABB3-48C431E398C4");
wp.setsPackName("insert");
wp.setsDescription(null);
wp.setdPackStartDate(null);
wp.setdPackEndDate(null);
wp.setiStatus((short)1);
wp.setuParentID(null);
wp.setfPMPlanWorkload(new java.math.BigDecimal(0));
wp.setiPriority((short)3);
wp.setsBizID(null);
wp.setsDeadwayMemo(null);
wp.setIsIteration((short)0);
wp.setProgressRate((short)20);
wp.setOwner("zhangxuebin WX208751");
wp.setScheduleStatus((short)0);
wp.setsCreator("zhangxuebin WX208751");
wp.setdCreateTime(new Date());
wp.setsModifiedUser("zhangxuebin WX208751");
wp.setsModifiedTime(new Date());
wp.setRemark(null);
wp.setKeyIn(null);
wp.setKeyOut(null);
wp.setWorkLineBase(new java.math.BigDecimal(0));
wp.setUpdateType(null);
wp.setPredecessors(null);
session.save(wp); //-------------------------------------------------------------
// Delete
//-------------------------------------------------------------
String hqlDelete = "delete WorkPack where uWorkPackID=:uWorkPackID";
Query queryDelete = session.createQuery(hqlDelete);
queryDelete.setParameter("uWorkPackID", wp.getuWorkPackID());
int resultDelete = queryDelete.executeUpdate(); trans.commit();
session.close(); // Print select results
for (WorkPack item : list) {
System.out.println(item.getsPackName());
} // Print update results
System.out.println(resultUpdate); // Print delete results
System.out.println(resultDelete); } }

事实上,insert的方法也可以使用Query的HQL直接操作。

参考引用:

http://www.cnblogs.com/wucg/archive/2012/06/04/2533537.html

[Hibernate] - Select/Update/Delete/Insert的更多相关文章

  1. create alter rename desc select update delete insert

    conn scott/root;create table student (id number(3), name varchar2(10), sex char(2), sno number(3));a ...

  2. [转]SQLServer添加UPDATE回滚日志(update/delete/insert)

    下面直接上代码(copy到你的数据库里面直接就可以运行): CREATE PROCEDURE [dbo].[SP_UPDATE_LOG] ) AS BEGIN SET NOCOUNT ON; IF N ...

  3. mysql5.7 闪回数据(update delete insert)

    本次测试用Myflash闪回dml操作,有个前提条件是log_bin开启并且log模式是row: mysql> show global variables like "binlog%& ...

  4. 廖雪峰Java15JDBC编程-2SQL入门-2insert/select/update/delete

    1. INSERT用于向数据库的表中插入1条记录 insert into 表名 (字段1,字段2,...) values (数据1,数据2,数据3...) 示例 -- 如果表存在,就删除 drop t ...

  5. 索引是否也能提高UPDATE,DELETE,INSERT速度 解释

    insert 不会提高,insert 用不到索引,只会增加维护索引的时间. update ,更新索引列不会提高,少量更新非索引列,会有提高 : 更新索引列,索引要重新维护,更新非索引列,倒是没什么影响 ...

  6. android sqlite select,update,delete语法

    String sql = "update recentsongtab set usetime=? , strdatetime=? where songid=?";//修改的SQL语 ...

  7. C++使用Mysql的详细步骤及各个常用方法的代码演示:select,insert,update,delete

    这几天一直在学习C++下使用Mysql的方法及其中各种的问题,也看了很多Mysql的API函数,当然自己看的还是很基础的.其实对于每种数据库的操作,基本的方法都是非常类似的,大多都是connect,s ...

  8. mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干

    1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...

  9. 数据操纵:SELECT, INSERT, UPDATE, DELETE

    SELECT 句法 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACHE ...

随机推荐

  1. Neutron Metering as a Service

    1, /etc/neutron/neutron.conf   service_plugins = router,metering    notification_driver=neutron.open ...

  2. OOP初学小结

    最近刚刚开始学python的OOP,感觉不太适应.一些很简单的程序也卡了好半天才能调好- 其中的一个错误是:将两个不同的类的方法互相调用,结果走进死循环- 另外就是debug的时候,不要在那里空空地望 ...

  3. CentOS下Web服务器环境搭建LNMP一键安装包

    CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...

  4. CSS2伪类选择器要点

    有四个选择器,分别是 hover:鼠标悬停 link:链接不能使用时 visited:链接被点击后 active:链接被点击时,如果鼠标不放,就会一直触发active属性 link在w3c中记录为链接 ...

  5. 阿里云2003服务器VPN搭建[转自阿里云官方论坛]

    VPN可以应用在很多方面,很多公司只是拿它接入公司内部网络,但我们做安全的需要的是利用它做跳板上网(还有提高网速).这篇文章主要是针对这种应用来说的,包括公网VPN的配置. 服务器配置 前奏:关闭防火 ...

  6. shell 脚本实战笔记(1)--source/fork/exec的区别

    在linux shell编程中, 随着脚本处理规模的变大, 会嵌套调用子进程. 但父进程以不同的方式调用子进程, 其结果和背后的机制不尽相同.这边就简单描述下source/fork/exec调用子进程 ...

  7. ZPPR032-批量展BOM

    *-----------------------------------------------------------------------REPORT zppr032 NO STANDARD P ...

  8. android listview去掉分割线

    1:android listview去掉分割线 1>设置android:divider="@null" 2>android:divider="#0000000 ...

  9. C#各类型大小

  10. CentOS搭建Httpd Pyhton3 Django环境

    系统环境 centos-6-x86 系统自带httpd 编译安装Python3 pip3 参考 http://www.cnblogs.com/vawter/p/6254170.html 编译安装wsg ...