关于spring Entity 在不同包下的无法扫描的解决方案

如果是jar 文件      在persistentUnit 定义中加上标签去指定扫描的包

 
  
 
        org.hibernate.ejb.HibernatePersistence
        
        libs/sqljdbc.jar
        
            
            
            
            
            
            
            
        
    

2
	显式扫描实体类。
 
  
 
  
 org.hibernate.ejb.HibernatePersistence
        
        
        
            


 
  
3 复杂解决方案1(未验证,仅引用其配置   )
	
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="lobHandler" ref="lobHandler"/>
<property name="packagesToScan">
    <list>
        <value>com.idc.scd.domainvalue>
        <value>com.idc.scd.domain.dropdownvalue>
        <value>com.idc.scd.domain.externalvalue>
        <value>com.idc.scd.domain.pkvalue>
    list>
property>
    <property name="hibernateProperties">
      <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialectprop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}prop>
        <prop key="hibernate.format_sql">${hibernate.format_sql}prop>
        <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}prop>
        <prop key="hbm2ddl.auto">validateprop>
        <prop key="hibernate.cache.use_query_cache">trueprop>
        <prop key="hibernate.connection.release_mode">after_statementprop>
        <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProviderprop>
        <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}prop>
        <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}prop>
        <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}prop>
        props>
    property>
bean>
 
  
 
  
 
  
4  自定义artifacts
   intellij -> project structure->Artifacts-> add-> war->  将依赖工程做为源代码导入war包,而不是jar, 就能解决扫描不到不同模块下的代码的问题。
   
  
 
  
 
  

你可能感兴趣的:(Spring,hibernate)