在jar中嵌入hibernate hbm.xml映射

Qui*_*Par 2 java embed hibernate hibernate-mapping

是否可以将hibernate映射hbm.xml嵌入到jar中,并避免在applicationContext.xml中手动引用

  <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
      <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">
          org.hibernate.dialect.MySQLDialect
        </prop>
      </props>
    </property>
    <property name="mappingResources">
      <list>
        <value>
          com/…/domain/Question.hbm.xml
Run Code Online (Sandbox Code Playgroud)

并指向jar/etc?
Nhibernate有这样一个选项指向一个程序集,从那里它拿起了hbm.
注释不是一种选择

编辑: 编辑:我的目的是删除对hbm的手动引用并指向一个通用的位置,hibernate可以从中获取它

  <list>
    <value>
      com/.../Question.hbm.xml
    </value>
    <value>com/.../Users.hbm.xml</value>
    <value>
      com/.../Answers.hbm.xml
    </value>
Run Code Online (Sandbox Code Playgroud)

del*_*ego 6

只是为了澄清一下:你特别是在谈论Spring和Hibernate,因为你展示的配置是Spring的Hibernate配置.Spring's LocalSessionFactoryBean接受多种不同的方法来设置Hibernate映射文件的位置; 你只显示了使用mappingResources的参数,但也有mappingLocations,mappingJarLocationsmappingDirectoryLocations.

我认为,对于您的示例,您可能希望使用mappingDirectoryLocations并将其指向JAR中的特定目录,例如:

<property name="mappingDirectoryLocations">
      <list>
        <value>
          com/…/domain/
        </value>
      </list>
</property>
Run Code Online (Sandbox Code Playgroud)