Free Monkey
Make Anything Mobile!
首页
新随笔
联系
聚合
管理
随笔-1 评论-68 文章-98 trackbacks-0
Hibernate FAQ(2)--分页显示和非主键的外键关联
1、分页显示
public
class
QuizRecordDAO
extends
BaseHibernateDAO
{
private
int
count;
public
int
getCount()
{
return
this
.count;
}
public
List list(
int
start,
int
range )
{
log.debug(
"
finding all QuizRecord instance
"
);
try
{
Criteria criteria
=
getSession().createCriteria( QuizRecord.
class
);
count
=
((Number) criteria .setProjection( Projections.rowCount() ).uniqueResult()).intValue();
criteria.setProjection(
null
);
//
criteria.addOrder( Order.desc( TYPE ) );
criteria.setFirstResult( start );
criteria.setMaxResults( range );
return
criteria.list();
}
catch
( RuntimeException re )
{
log.error(
"
find by property name failed
"
, re );
throw
re;
}
}
public
List list(
int
awardStatus,
int
start,
int
range )
{
log.debug(
"
finding all QuizRecord instance
"
);
try
{
Criteria criteria
=
getSession().createCriteria( QuizRecord.
class
);
criteria.add( Expression.eq( AWARD_STATUS, Integer.valueOf( awardStatus ) ) );
count
=
((Number) criteria .setProjection( Projections.rowCount() ).uniqueResult()).intValue();
criteria.setProjection(
null
);
//
criteria.addOrder( Order.desc( TYPE ) );
criteria.setFirstResult( start );
criteria.setMaxResults( range );
return
criteria.list();
}
catch
( RuntimeException re )
{
log.error(
"
find by property name failed
"
, re );
throw
re;
}
}
}
2/ 非主键的外键关联
<?
xml version="1.0"
?>
<!
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 - Hibernate Tools
-->
<
hibernate-mapping
>
<
class
name
="org.anymobile.admin.entity.QuizRecord"
table
="quiz_record"
catalog
="fetion"
>
<
id
name
="id"
type
="java.lang.Integer"
>
<
column
name
="id"
/>
<
generator
class
="increment"
></
generator
>
</
id
>
<
many-to-one
name
="yangzhouUser"
class
="org.anymobile.admin.entity.User"
fetch
="select"
property-ref
="fetionId"
>
<
column
name
="fetion_id"
length
="20"
not-null
="true"
/>
</
many-to-one
>
</
class
>
</
hibernate-mapping
>
-- property-ref="fetionId"是手工添加的代码
<?
xml version="1.0"
?>
<!
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 - Hibernate Tools
-->
<
hibernate-mapping
>
<
class
name
="org.anymobile.admin.entity.User"
table
="f_user"
catalog
="fetion"
>
<
id
name
="id"
type
="java.lang.Integer"
>
<
column
name
="id"
/>
<
generator
class
="increment"
></
generator
>
</
id
>
<
property
name
="fetionId"
type
="java.lang.String"
>
<
column
name
="fetion_id"
length
="10"
not-null
="true"
unique
="true"
/>
</
property
>
<
property
name
="phone"
type
="java.lang.String"
>
<
column
name
="phone"
length
="11"
/>
</
property
>
<
set
name
="records"
inverse
="true"
>
<!--
<key>
<column name="fetion_id" length="15" not-null="true" />
</key>
-->
<
key
column
="fetion_id"
property-ref
="fetionId"
/>
<
one-to-many
class
="org.anymobile.admin.entity.QuizRecord"
/>
</
set
>
</
class
>
</
hibernate-mapping
>
--绿色注释部分是Hibernate自动生成的,<key column="fetion_id" property-ref="fetionId"/>是手工添加的。
posted on 2009-04-22 00:02
Xu Jianxiang
阅读(1401)
评论(1)
编辑
收藏
所属分类:
Open Source
、
Java Tech
评论:
#
re: Hibernate FAQ(2)--分页显示和非主键的外键关联[未登录]
2011-12-08 11:35 |
JOJO
好厉害,解决了我的问题。(非主键)
不知道可否给再我讲讲原理呢,如果可以,请加Q1176792523。或者直接回复我
很感谢!
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
知识库
C++博客
博问
管理
相关文章:
Hibernate FAQ(2)--分页显示和非主键的外键关联
几个Java混淆器
Windows 2003下配置Apache虚拟主机
Windows 2003下配置Apache代理Tomcat集群
Struts FAQ
Hibernate FAQ
基于Struts和Hibernate的轻量级J2EE应用
Contributing to Eclipse(2)--Eclipse 插件
Contributing to Eclipse(1)--Eclipse SDK
Java与XML(2)--Apache XMLBeans
<
2024年11月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
随笔分类
Some Thing(1)
文章分类
Android(43)
Design Research(6)
Java Tech(13)
Life and Work(7)
Mobile Tech(4)
Open Source(16)
Other Tech(4)
Server Side(6)
Web 2.0(1)
Design Patterns
FluffyCat (Larry Truett)
J 道
良葛格
XMPP/Jabber
Aaron Johnson
bluemonkey 遥远的回忆
oranje的专栏
搜索
最新评论
1. re: Android 的系统属性(SystemProperties)设置分析
多福多寿
--困死了 草 够逼玩意
2. re: Introduction to Android Webkit[未登录]
1
--1
3. re: 随机生成N位数字/字母密码
好
--贾志高
4. re: Android手机上监听短信的两种方式
我不知道怎么玩
--刘中华
5. re: Android手机上监听短信的两种方式
问一下哈,我现在要处理大批的数据,然后在ContentObserver里面处理会Anr,能不能异步处理呢
--zrw