harryo
harryo

Reputation: 513

Configuring Hibernate XML with P-Namespace

I want to rewrite my sessionFactory bean using the p-namespace. I understand how to reference general objects, but I've never dealt with lists, props, etc. How would I go about writing , and so on?

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>

    <property name="mappingResources">
        <list>
            <value>/com/mysite/domain/Object.hbm.xml</value>
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
           <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
           <prop key="hibernate.show_sql">true</prop>
           <prop key="hibernate.hbm2ddl.auto">update</prop> 
        </props>
  </property>
</bean>

This is the code I have so far in p-namespace:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource"
    p:mappingResources-list="/com/mysite/domain/Object.hbm.xml" 
    p:hibernateProperties-props=""/>

Upvotes: 2

Views: 891

Answers (1)

Aravind A
Aravind A

Reputation: 9697

You cannot do this directly . You could use util:map though. Try

    <util:map id="hibernateConfig" >
        <entry key="hibernate.hbm2ddl.auto" value="update" />
        <entry key="hibernate.show_sql" value="true" />
        <!-- Other properties -->
    </util:map>

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
  p:dataSource-ref="dataSource"
  p:mappingResources-list="/com/mysite/domain/Object.hbm.xml" 
  p:hibernateProperties-ref ="hibernateConfig"/>

Check This for complete help on p:namespace

Upvotes: 2

Related Questions