SessionFactory.openSession(连接)在Hibernate 4中 [英] SessionFactory.openSession(Connection) in Hibernate 4
本文介绍了SessionFactory.openSession(连接)在Hibernate 4中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 SessionFactory.openSession(Connection)
抽取现有的JDBC连接。现在在4.0这种方法不可用。我应该使用哪种方法?
I am pumping existing JDBC connection using SessionFactory.openSession(Connection)
. Now in 4.0 this method is not available. Which method should I use for this?
推荐答案
您可以使用 SessionFactory.withOptions()和 SessionBuilder.connection(连接连接)。
SessionBuilder连接(连接连接)
为会话选项添加特定连接
Adds a specific connection to the session options
参数:
连接 - 要使用的连接。
Parameters: connection - The connection to use.
退货:this,for method chaining
Returns: this, for method chaining
<例子:
Example:
SessionBuilder sb = SessionFactory.withOptions();
Session session = sb.connection(connection).openSession();
这篇关于SessionFactory.openSession(连接)在Hibernate 4中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文