Sean Nguyen
Sean Nguyen

Reputation: 13168

How to config Spring to load hibernate mapping from jar?

My hibernate mapping is in a jar file for example: abc-1.0.1.jar. And the mapping files are: abc-1.0.1.jar/user.hbm.xml.

I can't get spring to load it correctly (I don't want to put my jar version in the mapping also). This is my configuration:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource"><ref local="DS"/></property>
        <property name="hibernateProperties">
           <ref bean="hibernateProperties" />
        </property>     
        <property name="mappingJarLocations" value="classpath*:abc-*.jar"></property>
    </bean>

There is no error at loading but the setting resource is an empty array. Can you help me figure out that is wrong?

Thanks,

Upvotes: 1

Views: 4872

Answers (2)

sellerjd
sellerjd

Reputation: 73

You can use a wildcard:

<property name="mappingJarLocations" value="WEB-INF/lib/abc-*.jar"/>

Upvotes: 0

Neeme Praks
Neeme Praks

Reputation: 9150

It seems you might want to use mappingLocations (JavaDoc) property, instead of mappingJarLocations. In that case, you would just specify classpath:user.hbm.xml:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource"><ref local="DS"/></property>
    <property name="hibernateProperties">
       <ref bean="hibernateProperties" />
    </property>
    <property name="mappingLocations" value="classpath:/user.hbm.xml"/>
</bean>

Upvotes: 3

Related Questions