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

时间:2022-03-14 17:42:06

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

 <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source></jta-data-source>
<jar-file>libs/sqljdbc.jar</jar-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />
<property name="hibernate.connection.url" value="jdbc:sqlserver://localhost:1433;databaseName=TEST" />
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="sa" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>

2
显式扫描实体类。
 
 <provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source></jta-data-source>
<class></class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />


 
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.domain</value>
<value>com.idc.scd.domain.dropdown</value>
<value>com.idc.scd.domain.external</value>
<value>com.idc.scd.domain.pk</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<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">validate</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.connection.release_mode">after_statement</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
<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 Entity 在不同包下的无法扫描的解决方案
  关于spring Entity 在不同包下的无法扫描的解决方案关于spring Entity 在不同包下的无法扫描的解决方案