文章列表
条件查询
session.createCriteria(Item.class);
session.createCriteria(java.lang.Object.class);
session.createCriteria(User.class).addOrder( Order.asc("lastname") ).addOrder( Order.asc("firstname") );
不必再session开启的条件下创建查询
DetachedCriteria crit =
DetachedCriteria.forClass(Us ...
创建查询对象
hql
Query hqlQuery = session.createQuery("from User");
原生语法
Query sqlQuery = session.createSQLQuery(
"select {user.*} from USERS {user}").addEntity("user", User.class);
Criteria
Criteria crit = session.createCriteria(User.class);
JPA
Query ejbQuery = ...
hibernate内建的开源产品提供的高速缓存
EHCache
(org.hibernate.cache.EhCacheProvider)
OSCache
(org.hibernate.cache.OSCacheProvider)
SwarmCache
(org.hibernate.cache.SwarmCacheProvider)
JBoss TreeCache
(org.hibernate.cache.TreeCacheProvider)
Each cache provides different capacities in terms of ...
延迟抓取
默认 lazy=true
<bag name="childCategories" table="CATEGORY" cascade="save-update" inverse="true" lazy="true">
<key column="PARENT_CATEGORY_ID" />
<one-to-many class="cascade.Category" / ...
动态数据过滤
定义数据过滤器
<filter-def name="limitItemsByUserRank">
<filter-param name="currentUserRank"" type="long"/>
</filter-def>
@org.hibernate.annotations.FilterDef(
name="limitItemsByUserRank",
parameters=@org.hibernate.ann ...
在插入时运行的触发器
<property name="created" insert="false" update="false"
column="CREATED" type="timestamp" />
User user = new User();
session.save(user);
session.flush();
session.refresh(user);
System.out.println(user.getCrea ...