Announcement Announcement Module
Collapse
No announcement yet.
Array of similar hibernate sessions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Array of similar hibernate sessions

    Hi,

    I need to use array of similar hibernate sessions in Spring web application. Sessions looks like:

    Code:
    <bean id="mySessionFactory1" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>product.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="myDataSource1"/>
    </property>
    </bean>
    Only dataSource property of Sessions are differ from each other.

    How can I define them without duplication?

  • #2
    You can use the parent/abstract attributes.
    First, you create a bean with attribute abstract="true" you call "sessionParent" for instance, and in which you define all common property as well as the class.
    Then you creates instances with
    Code:
    <bean id="session1" parent="sessionParent>
    <property name="dataSource">
      <ref bean="myDataSource1"/>
    </properties>
    </bean>
    You only have to tell the differences with the parent bean and you can reduce your typing a lot.

    HTH

    Comment

    Working...
    X