我是新的 Hibernate
学习者。
我很困惑,为什么我们在 hibernate 配置文件中使用标签 session-factory
?
我们还在主类中使用它来为所有事务创建 session 工厂对象。
最佳答案
在 hibernate 状态下 SessionFactory
用于管理数据库的 session 和事务,如 documentation 中所示。 :
The main contract here is the creation of Session instances. Usually an application has a single SessionFactory instance and threads servicing client requests obtain Session instances from this factory.
The internal state of a SessionFactory is immutable. Once it is created this internal state is set. This internal state includes all of the metadata about Object/Relational Mapping.
编辑:
<session factory>
XML配置文件中的标签用于配置和初始化 hibernate 的 session 工厂设置,例如Dialect
类和连接 Driver
类属性,您可以在 Hibernate - Configuration 中查看XML 配置文件必须符合 Hibernate 3 配置 DTD。
而sessionFactory
我们在类中使用的实例用于管理每个数据库事务的 session ,您可以在 jBossDeveloper's Sessions and transactions tutorial 中找到有关它的更多详细信息。 .
关于hibernate - hibernate配置文件中的session-factory标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697659/