文章分类 -  B3-hibernate

摘要:Hibernate中的增删查改操作都是通过session的方法进行一、查询session中查询有两种方法:get和load这两种方法都是返回实体对象,不同的是!如果未发现符合条件的记录,get会返回null而load会抛出一个ObjectNotFoundException异常。load方法可返回实体的代理类实例,而get方法永远直接返回实体类load方法可以充分利用内部缓存和二级缓存中的现有数据,而get方法则仅仅在内部缓存中进行数据查找,如果没有发现数据,将越过二级缓存,直接调用sql完成数据读取,有人称之为“懒加载”。get方法首先查询session缓存,没有结果!在查询二级缓存,最后查询 阅读全文
posted @ 2013-09-17 09:28 暖流 阅读(338) 评论(0) 推荐(0)
摘要:有这样一段代码,返回的list无法转换成User对象public List getStoreList(final int pageNo,final int pageSize,final String role,final String check) { //type is cpUser 商品type String hql=""; if(check.equals("通过")){ hql = "from User user inner join user.roles as role where role.name='" + rol 阅读全文
posted @ 2013-09-17 09:27 暖流 阅读(505) 评论(0) 推荐(0)
摘要:Hibernate有很多值得学习的地方,这里我们主要介绍Hibernate,包括介绍Hibernate PO和Hibernate VO方面。PO(Persistence Object )和VO(Value Object )是Hibernate中两个比较关键的概念。首先,何谓VO,很简单,VO就是一个简单的值对象。总结:VO经过Hibernate进行处理,就变成了PO。session.save(user)中,我们把一个VO “user”传递给Hibernate的Session.save方法进行保存。在save方法中,Hibernate对其进行如下处理:1.在当前session所对应的实体容器(E 阅读全文
posted @ 2013-09-17 09:23 暖流 阅读(2450) 评论(2) 推荐(1)
摘要://二进制大型对象(BLOB)列是MySQL的秘密武器之一。这些列中存储了二进制的数据,你可以象其它普通的数据类型一样来检索和操纵它。根据MySQL指南有关资料,BLOB是一个二进制大型对象,它能容纳不同大小的数据。事实上,MySQL有四种BLOB类型: //◆tinyblob:仅255个字符 //◆blob:最大限制到65K字节 //◆mediumblob:限制到16M字节 //◆longblob:可达4GB String fname = "c:\\itanger.gif";//要入库的文件 File f = new File(fname); FileInputStrea 阅读全文
posted @ 2013-09-16 13:49 暖流 阅读(508) 评论(0) 推荐(0)
摘要://Street.hbm.xml //当column不指定的时候默认是和name相同 //这里简单介绍,简单类型的配置标签,多对一的配置标签,以此xml为例,需要注意的是该xml是一个街道的实体映射,也就是说一个区可以包... 阅读全文
posted @ 2013-09-13 17:58 暖流 阅读(3095) 评论(0) 推荐(0)
摘要://String转换Date DateFormat datef = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = datef.parse(cd); public Map getSmsContentByCateoryIdOrDate(Long id, Date date) { Map map = new HashMap(); final String hq1 = "from SmsContent s where s.category.id="+id+" and s.deleteT 阅读全文
posted @ 2013-09-13 17:56 暖流 阅读(349) 评论(0) 推荐(0)
摘要://hibernate获取个数 public Long getStarLevel(Long id) { final String hql = "select count(*) from Activity act where act.orginator.id="+id; Long count = (Long)getHibernateTemplate().find(hql).listIterator().next(); return count; } //根据id修改一个对象属性 public String updateAttrNameByAttrValu... 阅读全文
posted @ 2013-09-13 17:53 暖流 阅读(308) 评论(0) 推荐(0)
摘要:public List getAllContentClickCount() { final String query = "select b.smsContentId as ContentId,count(*) as ClickCount from SmsContentClickLog b left join SmsContent a on b.smsContentId=a.id where a.deleted=1 group by b.smsContentId"; List list = (List)this.getHibernateTemplate().exec... 阅读全文
posted @ 2013-09-13 17:50 暖流 阅读(581) 评论(0) 推荐(0)
摘要:执行SQL插入this.getHibernateTemplate().executeUpdate(new HibernateCallback(){ public Object doInHibernate(Session s) throws HibernateException,SQLException{String sql = "insert into xxx(xxx,xxx)";session.createQuery(sql).executeUpdate();});} 更新表this.getHibernateTemplate.merge("TableName&q 阅读全文
posted @ 2013-09-13 17:49 暖流 阅读(815) 评论(0) 推荐(0)
摘要:import com.mobileares.dolphin.dao.ActivityDao;import com.mobileares.dolphin.dao.CommodityDao;import com.mobileares.dolphin.dao.UserDao;import com.mobileares.dolphin.model.*;import com.mobileares.dolphin.service.*;import org.hibernate.Hibernate;import org.junit.Test;import org.springframework.beans.f 阅读全文
posted @ 2013-09-13 17:47 暖流 阅读(210) 评论(0) 推荐(0)