Spring配置sessionFactory

2025-05-08 20:14:36
推荐回答(1个)
回答1:

不用dataSource引入hibernate.cfg.xml

  
              
                             classpath:hibernate.cfg.xml  
              

2.丢掉hibernate.cfg.xml

1>使用注解:

       class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
         
       annotatedClasses">  
      
             com.bjsxt.model.User  
             com.bjsxt.model.Log  
    
  
         
        
      
          
            org.hibernate.dialect.MySQLDialect  
          
        true  
    
  
        

2>不使用注解

    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
          
      
    mappingResources">  
      
        jsf/web/entity/User.hbm.xml  
    
  
      
          
      
          
              
              
                org.hibernate.dialect.MySQLInnoDBDialect  
              
            update  
              
            true  
              
            true  
        
  
      

 3>使用packagesToScan

    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
      
     packagesToScan">  
          
            com.bjsxt.model  
                  
        
  
      
      
          
              
                org.hibernate.dialect.MySQLDialect  
              
            true