【发布时间】:2011-07-19 18:49:02
【问题描述】:
Springapplication context中org.springframework.orm.hibernate3.LocalSessionFactoryBean类的Hibernate类映射如何配置?我想将session factory 类映射从以下hibernate.cfg.xml 移动到相应的Spring 会话工厂bean,以便我可以消除hibernate.cfg.xml。
文件hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- ... -->
<mapping resource="Queries.hbm.xml" />
<mapping class="com.company.app.common.model.Account" />
<mapping class="com.company.app.common.model.AccountCategory" />
<mapping class="com.company.app.common.model.AssetType" />
<mapping class="com.company.app.common.model.Book" />
<mapping class="com.company.app.model.AssetTypeCategory" />
<!-- ... -->
</session-factory>
</hibernate-configuration>
文件spring-application-context.xml:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<!-- Instead of the above, I want to use the following. Where and
how do I define the class mappings so that I may eliminate
hibernate.cfg.xml? -->
<--
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>Queries.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
-->
</bean>
【问题讨论】:
-
我想通过将
hibernate.cfg.xml文件的内容移动到 Spring 应用程序上下文中来消除它。 -
这些是带注释的实体类吗?
-
是的,这些是带注释的类。
标签: java hibernate spring configuration