使用P-Namespace配置Hibernate XML

时间:2012-01-03 03:53:32

标签: java xml hibernate spring

我想使用p-namespace重写我的sessionFactory bean。我理解如何引用一般对象,但我从未处理过列表,道具等。我将如何进行写作,等等?

<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>

这是我目前在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=""/>

1 个答案:

答案 0 :(得分:2)

你不能直接这样做。你可以使用util:map。试试

    <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"/>

检查This以获取有关p:namespace

的完整帮助