- 浏览: 464532 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
chexiazi:
一样的xml代码 报这个错 <ns1:XMLFault ...
CXF 通过用户名和密码进行验证 -
di1984HIT:
谢谢啊 ~~~
通过JavaCompiler进行编译java文件(转载) -
aa00aa00:
'%${userName}%' 这种是可以的,是可以模糊查询的 ...
mybatis 模糊查询 -
一棵杨柳的地盘:
我把你的代码不了一遍 但是汇报错首先:static { ...
CXF 通过用户名和密码进行验证 -
shangmin1990:
转 IntelliJ IDEA 编辑器生成 Hibernate 实体映射文件
customer2的配置文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.bsw.job.Customer2" table="customer2" catalog="hibernateex">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="20" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="30" />
</property>
<property name="address" type="java.lang.String">
<column name="address" length="30" />
</property>
</class>
</hibernate-mapping>
Customer2DAO 类
package com.bsw.job;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
/**
* Data access object (DAO) for domain model class Customer2.
*
* @see com.bsw.job.Customer2
* @author MyEclipse Persistence Tools
*/
public class Customer2DAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(Customer2DAO.class);
public List selectCustomer(String name){
String hql="from Customer2 where name =:name order by age";
Query query =getSession().createQuery(hql);
query.setParameter("name", name);
List list=query.list();
return list;
}
public List selectAllCustomer(){
String hql="from Customer2 order by age";
Query query =getSession().createQuery(hql);
List list=query.list();
return list;
}
public void deleteCustomer(Customer2 customer){
Transaction tr=getSession().beginTransaction();
getSession().delete(customer);
tr.commit();
getSession().close();
}
public void updateCustomer(Customer2 customer){
Transaction tr=getSession().beginTransaction();
getSession().saveOrUpdate(customer);
tr.commit();
getSession().close();
}
public void addCustomer(Customer2 customer){
Transaction tr=getSession().beginTransaction();
getSession().save(customer);
tr.commit();
getSession().close();
}
public void save(Customer2 transientInstance) {
log.debug("saving Customer2 instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Customer2 persistentInstance) {
log.debug("deleting Customer2 instance");
try {
Transaction tr=getSession().beginTransaction();
getSession().delete(persistentInstance);
tr.commit();
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Customer2 findById(java.lang.Integer id) {
log.debug("getting Customer2 instance with id: " + id);
try {
Customer2 instance = (Customer2) getSession().get(
"com.bsw.job.Customer2", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Customer2 instance) {
log.debug("finding Customer2 instance by example");
try {
List results = getSession().createCriteria("com.bsw.job.Customer2")
.add(Example.create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Customer2 instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Customer2 as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findAll() {
log.debug("finding all Customer2 instances");
try {
String queryString = "from Customer2";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Customer2 merge(Customer2 detachedInstance) {
log.debug("merging Customer2 instance");
try {
Customer2 result = (Customer2) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Customer2 instance) {
log.debug("attaching dirty Customer2 instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Customer2 instance) {
log.debug("attaching clean Customer2 instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
测试类
package com.bsw.test;
import java.util.List;
import com.bsw.job.Customer2;
import com.bsw.job.Customer2DAO;
public class TestCustomer2 {
public static void main(String[] args) {
Customer2DAO dao=new Customer2DAO();
List<Customer2> list=(List<Customer2>)dao.selectAllCustomer();
System.out.println("按年龄从小到大排:");
System.out.println("用户ID "+"姓名 "+"年龄 "+"邮箱 "+"地址");
//for(Customer2 customer:list){
Customer2 customer=new Customer2();
customer.setAddress("上帝");
customer.setAge(25);
dao.addCustomer(customer);
Customer2 customer1=new Customer2();
//dao.getSession().get("customer1", 7);
customer1.setAddress("上帝");//在此处用这样就删不掉,还会报错,因为没有持久化,但如果用customer1.setId(7);的话就不会报错,因为在session.delete()方法中可以根据id把你所传的customer1给内部持久化。
dao.deleteCustomer(customer1);
//}
}
}
发表评论
-
java 位运算总结
2018-10-23 11:14 0<div class="iteye-blog- ... -
java sort 排序中的自然序排序总结
2018-10-23 11:07 5777<div class="iteye-blo ... -
Java内存分析工具
2012-11-24 11:16 2237Java运行时数据区包含:Method area, heap, ... -
转 StringUtils.isBlank()函数(分享一下)
2012-02-15 10:23 2956StringUtils的isBlank与isEmply ... -
jquery 使用ajax 提交整个表单的数据
2012-01-06 14:52 5888在使用Struts开发项目的时候发现很爽的一件事就是可以不使用 ... -
struts2 通配符
2011-12-31 16:25 1256在使用struts2时,如果想定义action的话可以这样做 ... -
Maven Web项目部署到Tomcat下
2011-12-30 17:28 19502通过Maven来搭建项目是 ... -
velocity与servlet的整合
2011-12-28 21:07 1420第一天学习velocity,参考别人的blog写了一个与Se ... -
ibatis 与spring3整合
2011-12-28 13:01 5701spring与ibates整合,使用 ... -
ibatis 入门
2011-12-28 12:48 1248昨天学习了一下ibatis ... -
转 JTA简介
2011-12-26 17:47 1043Java Transaction API(Java事务 ... -
转 IntelliJ IDEA 编辑器生成 Hibernate 实体映射文件
2011-12-23 16:03 23334很多人不知道怎么用 IntelliJ IDEA 编辑器 ... -
转 IntelliJ IDEA 使用基础篇 Java IDE编辑器
2011-12-23 15:02 8487IntelliJ IDE ... -
转在CXF中用JAXB数据绑定支持Map类型
2011-12-05 16:38 5189一些java类型不能自然映射成xml,例如,HashMap ... -
cxf wsdltojava 构造方法报错
2011-12-05 14:23 1295I'm marking this as "n ... -
(转)Struts2学习笔记--Internationalization
2011-11-21 18:13 1266Struts2 的国际化 ======== ... -
单例模式
2011-11-18 20:47 983单例模式(SINGLETON):单例模式确保某一个类只有一个实 ... -
类加载的顺序
2011-11-17 21:40 1157写道 package com.wang; public cl ... -
socket实现客户端与客户端通信
2011-11-17 19:34 3016最近闲来无聊,看了一下socket通信,实现了一个最简版的客户 ... -
接口设计的 11 种原则
2011-05-02 21:02 27127种设计坏味道 1.僵化性: 很难对系统进行改动,因为每个改动 ...
相关推荐
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
理解集合的性能 14.1.1. 分类 14.1.2. Lists, maps 和sets用于更新效率最高 14.1.3. Bag和list是反向集合类中效率最高的 14.1.4. 一次性删除(One shot delete) 14.2. 用于延迟装载的代理 14.3. ...
这个程序时学习struts+hibernate的比较好的例子,这个系统是我在网上找到的。不过不是用的tomcat... 为了减少网络传输,我把系统运行依赖的struts,hibernate等的jar包都删除了,所以请朋友们运行时自行加上,谢谢!
8.2 理解Session的缓存 8.2.1 Session的缓存的作用 8.2.2 脏检查及清理缓存的机制 8.3 Java对象在Hibernate持久化层的状态 8.3.1 临时对象的特征 8.3.2 持久化对象的特征 8.3.3 被删除对象的特征 ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
本章还将介绍通过Hibernate API来保存、修改和删除具有关联关系的对象的方法。 7.1 建立多对一的单向关联关系 148 7.1.1 [many-to-one]元素的not-null属性 153 7.1.2 级联保存和更新 155 7.2 映射一对多双向关联...
Hibernate持久化对象的生命周期 持久化对象的状态: 瞬时对象(Transient Objects)持久化对象(Persist Objects)、离线对象(Detached ...在Hibernate应用中Java对象的状态 Session的保存、更新、删除、查询方法:
删除持久对象 10.9. 在两个不同数据库间复制对象 10.10. Session刷出(flush) 10.11. 传播性持久化(transitive persistence) 10.12. 使用元数据 11. 事务和并发 11.1. Session和事务范围(transaction scope) ...
20.5. 理解集合性能(Understanding Collection performance) 20.5.1. 分类(Taxonomy) 20.5.2. Lists, maps 和sets用于更新效率最高 20.5.3. Bag和list是反向集合类中效率最高的 20.5.4. 一次性删除(One ...
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
因此想要下载此项目源码的读者必须用10积分才能下载,希望读者能理解.也希望你能从这个代码中能够很好的利用它. 注:里面的数据库文件都放在datebase目录下.(由于此处描述不支持图片功能,因此不能很好的展示效果图)...
理解集合的性能 14.1.1. 分类 14.1.2. Lists, maps 和sets用于更新效率最高 14.1.3. Bag和list是反向集合类中效率最高的 14.1.4. 一次性删除(One shot delete) 14.2. 用于延迟装载的代理 14.3. ...
基于JAVA毕业设计-JAVA struts+hibernate实现的网络购物系统.zip 这个程序时学习struts+hibernate的... 为了减少网络传输,我把系统运行依赖的struts,hibernate等的jar包都删除了,所以请朋友们运行时自行加上,谢谢!
19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率最高的 19.5.4. 一次性删除(One ...
20.5. 理解集合性能(Understanding Collection performance) 20.5.1. 分类(Taxonomy) 20.5.2. Lists, maps 和sets用于更新效率最高 20.5.3. Bag和list是反向集合类中效率最高的 20.5.4. 一次性删除(One...