spring4配置hibernate3

阅读更多

0. 前言

本文章所有代码已经上传,可以免费下载了解。

本项目启动的是会自动创建表结构,只需要看客们提供数据库支持。

本文为作者研究时所写,如有错误望指教。

 

1. 准备

jdk:1.7

eclipse:4.4

maven:3.1.1

spring:4.1.6

hibernate:3.6.10

 

2. 创建一个maven项目,并配置pom文件


	4.0.0
	org.xkx
	spring4-hibernate3-demo
	jar
	0.0.1-SNAPSHOT
	spring4-hibernate3-demo
	http://maven.apache.org
	

		
            oracle
            oracle-ojdbc6
            1.0
            system
            ${project.basedir}/lib/ojdbc6.jar
        
        

		
			org.hibernate
			hibernate-entitymanager
			3.6.10.Final
		


		
			commons-dbcp
			commons-dbcp
			1.4
		


		
			org.springframework
			spring-context
			4.1.6.RELEASE
		
		
			org.springframework
			spring-orm
			4.1.6.RELEASE
		
		
			org.springframework
			spring-aspects
			4.1.6.RELEASE
		


		
			junit
			junit
			4.10
			test
		
	
	
		spring4-hibernate3-demo
	

3. 编写spring配置文件



	
    
    

	
		
		
		
		
		
	


	
		
			
		
		
			
				
				hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
				
				hibernate.show_sql=true
				
				hibernate.format_sql=true
				
				hibernate.cache.use_second_level_cache=false
				
				hibernate.cache.use_query_cache=false
				
				hibernate.jdbc.fetch_size=50
				
				hibernate.jdbc.batch_size=50
				
				hibernate.hbm2ddl.auto=update
			
		
		
		
			org.xkx
		
	

	
	
		
	

    
        
        	
			
            
            
            
            
            
            
            
            
        
    
	
	
        
        
    

 

 4. JavaBean和service类请参见附件

 

 5. 编写测试类

    	ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring/srping-ctx.xml");
    	UseAnnotationEntityService useAnnotationEntityService = applicationContext.getBean("useAnnotationEntityServiceImpl", UseAnnotationEntityService.class);
    	for (int i = 0; i < 2; i++) {
    		UseAnnotationEntity useAnnotationEntity = new UseAnnotationEntity();
    		useAnnotationEntity.setName("姓名" + i);
    		useAnnotationEntity.setAge(i);
    		useAnnotationEntity.setCreateTime(new Date());
    		useAnnotationEntityService.create(useAnnotationEntity);
    		System.out.println("a");
    	}

 6. 执行测试代码


spring4配置hibernate3_第1张图片
 

 

  • spring4配置hibernate3_第2张图片
  • 大小: 662.6 KB
  • spring4-hibernate3-demo.zip (2.5 MB)
  • 下载次数: 26
  • 查看图片附件

你可能感兴趣的:(spring,hibernate,maven,spring4,hibernate3)