Spring整合Hibernate的两种方式

在使用spring注解整合hibernate时出现"org.hibernate.MappingException: Unknown entity: com.ssh.entry.Product“异常的问题。

最后找到了问题,总结一下

1.spring整合hibernate,取代*.hbm.xml配置文件
  在applicationContext.xml文件中配置方式

         class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
                 
                
                
                    classpath*:com/jxc/entity/*.hbm.xml
                
                  
                
                
                    
                        org.hibernate.dialect.MySQLDialect
                        update
                        true
                        true
                    
                
        

上面是以前的代码拿来对比下

spring整合hibernate,使用注解的方式
    在applicationContext.xml文件中配置方式

    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        
        
        
        
        
        
            
                true
                true
                update
                org.hibernate.dialect.MySQLDialect
            
        
        
    

上面其中一段或者替换为:


            
                com.kaspar.product.model 
            

这是第二种使用注解的方式。两种方式只有在引入映射文件或者注解类时候有差别 。

第一次整合注解时候,出现: "org.hibernate.MappingException: Unknown entity: com.ssh.entry.Product"

这里引入路径,只需要进入到包名就可以。

你可能感兴趣的:(Spring整合Hibernate的两种方式)