1.最近用hibernate 学会很多知识,总结如下:
(1)数据库表格已经设置默认值,在进行数据插入的时候,bean里面不赋值的话,插入之后该字段依旧是null
<property name="account" type="java.lang.String" insert="false"> <column name="account" length="100" /> </property>
加入insert="false" 就可以使它插入时不再对该字段进行操作,此值默认为true。同理update
(ii)注释方式:
@Column(insertable=false) public Integer getOrderNo() { return orderNo; } public void setOrderNo(Integer orderNo) { this.orderNo = orderNo; }
以下是他人总结内容(原帖地址:http://blog.csdn.net/xzknet/article/details/3905741)
Disjunction disjunction = Restrictions.disjunction(); Criterion cirterion = Restrictions.sqlRestriction("SIMULPORTCAPACITY<SIMULPORTCAPACITYOCUPIED".toLowerCase()); disjunction.add(cirterion); cirterion = Restrictions.sqlRestriction("ADSLPORTCAPACITY<ADSLPORTCAPACITYOCCUPIED".toLowerCase()); disjunction.add(cirterion); cirterion = Restrictions.sqlRestriction("LANPORTCAPACITY<LANPORTCAPACITYOCCUPIED".toLowerCase()); disjunction.add(cirterion); // ONU端口,至少要录入一种端口 Conjunction conjunction = Restrictions.conjunction(); cirterion = Restrictions.eq("lanportcapacity", 0); conjunction.add(cirterion); cirterion = Restrictions.eq("simulportcapacity", 0); conjunction.add(cirterion); cirterion = Restrictions.eq("adslportcapacity", 0); conjunction.add(cirterion); disjunction.add(conjunction); queryCriteria.add(disjunction); }
构造出的sql语句如下:
select * from aaaa this_ where (simulportcapacity < simulportcapacityocupied or adslportcapacity < adslportcapacityoccupied or lanportcapacity < lanportcapacityoccupied or (this_.LANPORTCAPACITY = ? and this_.SIMULPORTCAPACITY = ? and this_.ADSLPORTCAPACITY = ?))
List cats = sess.createCriteria(Cat.class) .add(Restrictions.like("name","Fritz%")) .add(Restrictions.between("weight",minWeight,maxWeight)) .list();
可以使用org.hibernate.criterion.Order来为查询结果排序.
List cats = sess.createCriteria(Cat.class) .add(Restrictions.like("name","F%") .addOrder(Order.asc("name")) .addOrder(Order.desc("age")) .setMaxResults(50) .list();
(未完)
hibernate 学习知识总结,布布扣,bubuko.com
原文:http://www.cnblogs.com/cuiyf/p/3704567.html