Hibernate3迁移到hibernate4

来自ling
跳转至: 导航搜索
  1. 配置切换
#hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.jdbc.fetch_size=100
hibernate.jdbc.batch_size=50
#hibernate.hbm2ddl.auto=update
hibernate.hbm2ddl.auto=none
hibernate.show_sql=true
hibernate.format_sql=false

#hibernate3
#hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
#hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
#hibernate.dataSource=org.springframework.jdbc.datasource.DriverManagerDataSource
#hibernate.sessionFactory=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
#hibernate.transactionManager=org.springframework.orm.hibernate3.HibernateTransactionManager
#hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
#hibernate4
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
hibernate.dataSource=org.apache.commons.dbcp.BasicDataSource
hibernate.sessionFactory=org.springframework.orm.hibernate4.LocalSessionFactoryBean
hibernate.transactionManager=org.springframework.orm.hibernate4.HibernateTransactionManager
hibernate.query.factory_class=org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
  1. BaseDaoSimple代码大调整
  2. BaseDaoSimple和BaseDao必须使用注解方式,不然getSession无效
protected Session getSession() {
		 //事务必须是开启的(Required),否则获取不到
        return sessionFactory.getCurrentSession();
	}