我们正在将Hibernate 3和Spring 3升级到Hibernate4和Spring4。
我在Hibernate 4中的sessionfactory代码如下所示。
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
public class PMLSessionFactoryBean extends LocalSessionFactoryBean {
private DialectMappingsLocator dialectMappingsLocator;
/**
* @param dialectMappingsLocator The dialectMappingsLocator to set.
*/
public void setDialectMappingsLocator(DialectMappingsLocator dialectMappingsLocator) {
this.dialectMappingsLocator = dialectMappingsLocator;
}
@Override
protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder localSessionFactoryBuilder){
SessionFactory sessionFactory = null;
Configuration configuration = super.getConfiguration();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(builder.build());
return sessionFactory;
}
}
我的应用程序上下文xml如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="PMLJdbcProperties" class="com.fusionone.core.util.FilteredProperties">
<property name="location" value="classpath:jdbc.properties" />
<constructor-arg value="pml" />
</bean>
<bean id="PMLDataSource"
class="com.fusionone.core.db.pool.MonitoredDataSourceFactory"
destroy-method="close" factory-method="createDataSource">
<constructor-arg ref="PMLJdbcProperties" />
</bean>
<bean id="PMLDefaultDialectSettings" class="com.fusionone.pml.bean.PMLDialectMappings"
lazy-init="true" autowire-candidate="false">
<property name="mappingResources">
<list>
<value>hibernate-mappings/BrewApp.hbm.xml</value>
<value>hibernate-mappings/ExtShare.hbm.xml</value>
<value>hibernate-mappings/MergedContact.hbm.xml</value>
<value>hibernate-mappings/MergedContactLink.hbm.xml</value>
</list>
</property>
<property name="daoInterfaceImpls">
<map>
<entry key="DeletedContactDao"
value="com.fusionone.pml.dao.hibernate.DeletedContactDaoImpl" />
<entry key="ExtShareDao"
value="com.fusionone.pml.dao.hibernate.ExtShareDaoImpl" />
<entry key="MergedContactDao"
value="com.fusionone.pml.dao.hibernate.MergedContactDaoImpl" />
<entry key="MergedContactLinkDao"
value="com.fusionone.pml.dao.hibernate.MergedContactLinkDaoImpl" />
</map>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="PMLSessionFactory" />
</property>
<property name="nestedTransactionAllowed" value="true" />
</bean>
<bean id="PMLSessionFactory" class="com.fusionone.pml.bean.PMLSessionFactoryBean">
<property name="dataSource">
<ref bean="PMLDataSource" />
</property>
<property name="dialectMappingsLocator" ref="dialectMappingsLocator" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.jdbc.use_get_generated_keys">
false
</prop>
<prop key="hibernate.cache.region.provider_class">
org.hibernate.cache.ehcache.EhCacheRegionFactory
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.jdbc.batch_size">150</prop>
</props>
</property>
</bean>
以前在Hibernate 3的super.configuration中加载了所有的import,namedqueries和collections。当我们升级到hibernate 4时,我们没有看到任何导入,并且namedqueries正在加载到configuraiton。我的事务管理器正在加载pmlsessionfactory和pmlsessionfactorybean加载我的数据源和映射。调试时我们看到配置加载我的数据源和hibernate属性值意味着每个东西都加载了数据源名称和模式名称。但是没有加载命名查询,导入,集合和表。
我的代码或应用程序xml有什么问题吗?我们有自己的数据源类,它将具有所有连接池机制。此外,我修改了很多导入,而升级到Hibernate 4导致了这个问题,或者我需要添加更多像jar这样的东西。我使用的是hibernate-core 4.3.11,hibernate-ehcache 4.3.11,ehcache.2.7.0,hibernate-jpa-2.1-api.1.0.0 final,hibernate-entitymanager.4.3.11,hibernate-commons-annotations 4.0 .5和myclasspath中的infinitespan jar。我根据以下链接添加了罐子。
https://jsoftbiz.wordpress.com/2013/03/14/hibernate-4-and-ehcache-higher-than-2-4-3/
答案 0 :(得分:0)
我在下面的代码中添加了我的sessionfactory。现在我可以看到所有导入,命名查询和集合。
var nodeR = search.findNode(fileNodeRef);
alert(nodeR);