会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
刘政道 - 应用程序框架
《31天学会CRM项目开发(C#编程入门及项目实战)》作者,IT经理,程序员
博客园
::
新随笔
::
联系
::
管理
Hibernate Session
Posted on
2009-10-10 08:20
刘政道
阅读(
214
) 评论(
0
)
收藏
举报
Code
1
import
org.hibernate.cfg.
*
;
2
import
org.hibernate.Query;
3
import
org.hibernate.Session;
4
import
org.hibernate.SessionFactory;
5
import
org.hibernate.Transaction;
6
7
public
class
myCLass
8
9
{
10
11
public
static
Session session;
12
public
static
SessionFactory sessionFactory;
13
14
public
main()
15
{
16
17
//
Hibernate Configuration
18
if
(configuration
==
null
)
19
{
20
configuration
=
new
Configuration().configure();
21
}
22
if
(sessionFactory
==
null
)
23
{
24
sessionFactory
=
configuration.buildSessionFactory();
25
}
26
if
(session
==
null
)
27
{
28
session
=
sessionFactory.openSession();
29
}
30
31
}
32
33
public
void
queryMethod()
34
35
{
36
37
Query query
=
session.getNamedQuery(
"
hibernate sql
"
);
38
39
query.setParameter(
"
id
"
,orgId);
40
41
List list
=
query.list();
42
43
}
44
45
}
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3