JiveJdon Community Forums
在线441人   首页   主题表   培训咨询   标签   精华   查搜   注册    登陆 RSS
首页 » 论坛 » 开源项目大家谈
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 6 回复 / 1
 发表新帖子   回复该主题贴
zhengzhiyong

悄悄话
发表文章: 18
注册时间: 2002年12月12日 10:03
如何管理hibernate 的session? 2003年08月16日 09:21 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表
我在dao里用到Hibernate操作数据库,在业务逻辑里的方法里,如增加,修改
,删除,SessionFactory在此业务逻辑里构建一个实例.我的session是在每个方法里都要如此 session = sessionFactory.openSession();
执行玩操作后,session.close().
但是如果在一个方法里调用另外一个方法,会提示session已被close.
一个bean,最好用一个session.
不知各位大虾是怎么用session的.用一个session是否行的通?
初学,谢了各位!
fahrenheit

悄悄话
发表文章: 15
注册时间: 2003年04月24日 22:03
Re: 如何管理hibernate 的session? 2003年08月16日 09:31 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
把session传过去
zhengzhiyong

悄悄话
发表文章: 18
注册时间: 2002年12月12日 10:03
Re: 如何管理hibernate 的session? 2003年08月16日 10:19 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
我笨:)
能详细点吗?
bruce

悄悄话
发表文章: 191
注册时间: 2003年05月28日 09:53
Re: 如何管理hibernate 的session? 2003年08月23日 05:32 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
你这样试试看行不行。 例如MethodA中有调methodB的代码: callB,你就可以这样写callB(session s),然后在B方法中直接用s.save() and so on.Good luck.成与不成,给个回复.
robbin

悄悄话
发表文章: 589
注册时间: 2003年06月18日 09:32
Re: 如何管理hibernate 的session? 2003年08月23日 10:56 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
用ThreadLocal管理session

http://hibernate.bluemars.net/42.html
zhengzhiyong

悄悄话
发表文章: 18
注册时间: 2002年12月12日 10:03
Re: 如何管理hibernate 的session? 2003年08月23日 11:49 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
谢谢各位,马上试一下!:)

不过现在有个新问题,请指教:
一个表Result,有两个主键,分别是customerId,setDate,用Hibernate生成一个单独的主键类ResultPK.
现在我想查询表中所有customerId='0001'的记录,怎么写HQL语句???
我写的HQL语句:

//首先给主键表赋值
ResultPK resultPK = new ResultPK(); //结算主键表
resultPK.setCustomerId("0001");

//注:comp_id是Result类中ResultPK的实例
session.find("select result.comp_id from Result result where result.comp_id = "+resultPK+" ");

运行时出现错误:
net.sf.hibernate.QueryException: path expression ends in a composite value: result0_.comp_id [select result.comp_id from com.persistent.Result result where result.comp_id = com.persistent.ResultPK@11946c2[customerId=0001,setDate=<null>] ]

我不知道这样的语句怎么写?请大家帮帮忙!
先谢了。
xxmouse

悄悄话
发表文章: 18
注册时间: 2003年03月30日 02:13
Re: 如何管理hibernate 的session? 2003年09月08日 14:22 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
the idea is simple;
say, you have a composite-id in your Class Result, let assume that the name of it is "id" (and of course, id has two attributes: "customerId" and "setDate"), so we write the following sniplet to retrieve all the records in this table whose customerId='0001'.

select * from Result result where result.id.customerId='0001',

understand? just use double quote marks to enclose it in your HQL and you should be able to get it.
cheers
这个主题有 6 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
正在读取,请等待...
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
  每2分种自动备份发贴内容Ctrl-V粘贴取出,提问题前先查询标签列表

RSS 手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com

anti spam