Announcement Announcement Module
Collapse
No announcement yet.
Merging HBM Files from Multiple Application-context.xml files onto a single context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merging HBM Files from Multiple Application-context.xml files onto a single context

    Hi,

    I have a requirement with Spring and hibernate, My project has 4 modules each of which is a separate jar file containing its own application-context.xml and its own set of HBM files.

    The requirement is if i create a new module , i need to find a way where in i specify an option to merge all the HBM files from the other modules into the newly created application-context file. and also i need to maintain only one session factory across all the Application-context files.

    I appreciate early help.

    Thanks in advance
    Trilok

  • #2
    Lucky you

    I just had this problem last week

    The key is to use mappingLocations

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" destroy-method="destroy">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    </props>
    </property>
    <property name="mappingLocations">
    <list>
    <value>classpath:**/*.hbm.xml</value>
    </list>
    </property>
    </bean>

    Comment


    • #3
      THanks for the Reply. I tried this solution but still it couldnt resolve the HBM mappings. I just came to know that using classpath doesnt always work in weblogic, Is there any alternative solution to this problem?

      Comment


      • #4
        <property name="mappingLocations">
        <value>classpath*:**/*.hbm.xml</value>
        </property>
        <property name="hibernateProperties">


        when i use this code i am getting an exception

        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'filterInvocationInterceptor' defined in ServletContext resource [/WEB-INF/web-acegi-security.xml]: Cannot resolve reference to bean 'customPathBasedFilterInvocationDefinitionMap' while setting bean property 'objectDefinitionSource'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'customPathBasedFilterInvocationDefinitionMap' defined in ServletContext
        resource [/WEB-INF/web-acegi-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class
        Constructor threw exception; nested exception is org.springframework.orm.hibernate3.HibernateQueryE xception: SecureResourceClass is not mapped [select SC.fullyQualifiedResourceName from SecureResourceClass as SC

        Comment


        • #5
          one application context

          Originally posted by trilok007 View Post
          Hi,

          I have a requirement with Spring and hibernate, My project has 4 modules each of which is a separate jar file containing its own application-context.xml and its own set of HBM files.

          The requirement is if i create a new module , i need to find a way where in i specify an option to merge all the HBM files from the other modules into the newly created application-context file. and also i need to maintain only one session factory across all the Application-context files.

          I appreciate early help.

          Thanks in advance
          Trilok
          if you are thinking of using one application context, you can do something like this:
          Code:
          		<bean id="SubmissionDAO"
          			class="com.logixplayer.pf.dao.SubmissionDAO">
          			<property name="entityManagerFactory"
          				ref="entityManagerFactory" />
          		</bean>
          		<import resource="application-context-iAttributesService.xml"/>
          		<import resource="application-context-iCategoryService.xml"/>
          		<import resource="application-context-iTopicService.xml"/>
          		
          	</beans>
          where you import other application contexts into one application context. In your care you might have to use "classpath:data-access-context.xml", the "classpath:" prefix in front of your application contexts so your spring contexts can be found on your class path.
          From that point on, you can use a factory to get your beans like so:
          Code:
          package com.logixplayer.pf.service;
          
          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
          
          public class DataAccessServiceFactory {
          
          	private static ApplicationContext applicationContext;
          	private static final Log log = LogFactory.getLog(DataAccessServiceFactory.class);
          
          	public synchronized static ApplicationContext getApplicationContext() {
          		if (applicationContext == null) {
          			applicationContext = new ClassPathXmlApplicationContext("data-access-context.xml");
          		}
          		return applicationContext;
          	}
          
          	@SuppressWarnings("unchecked")
          	public static <T> T getBean(String beanName) {
          		return (T) getApplicationContext().getBean(beanName);
          	}
          
          
          }
          where "data-access-context.xml" is your main application context that has the other spring application contexts imported.
          Hope that helps.

          Comment


          • #6
            Hi logixplayer

            thanks for ur reply
            can please clarify me with the method DataAccessServiceFactory
            whr is it called from.

            thanks in advance

            Comment


            • #7
              ClassPathXmlApplicationContext

              Originally posted by santyop View Post
              Hi logixplayer

              thanks for ur reply
              can please clarify me with the method DataAccessServiceFactory
              whr is it called from.

              thanks in advance
              Ideally, I think it can be called from anywhere because you are using ClassPathXmlApplicationContext:
              Code:
              applicationContext = new ClassPathXmlApplicationContext("data-access-context.xml");
              This is the definition of ClassPathXmlApplicationContext:
              Code:
              Standalone XML application context, taking the context definition files from the class path. Mainly useful for test harnesses, but also for application contexts embedded within JARs.
              reference:http://static.springsource.org/sprin...onContext.html
              It also states:
              Code:
              This is a simple, one-stop shop convenience ApplicationContext. Consider using the GenericApplicationContext class in combination with an XmlBeanDefinitionReader  for more flexible context setup.

              so to answer you question, it can be used anywhere. You will feed the ClassPathXmlApplicationContext your application context file on the classpath. For myself, I used this factory in the same project as was my my master application-context file (which other context files linked to).

              Comment


              • #8
                hey thank you logixplayer for your help....
                can i keep different hbm files of different projects at one place......rather than importing the application context files of different projects....

                Comment


                • #9
                  hbm files

                  Originally posted by santyop View Post
                  hey thank you logixplayer for your help....
                  can i keep different hbm files of different projects at one place......rather than importing the application context files of different projects....
                  I think that would probably be the best thing to do.
                  I have a project called "Data Access" where everything related to data access is (databases), which is all my hibernate configurations.

                  Comment


                  • #10
                    I mean rather than mentioning all the names of hbm files i wud rather want something like

                    <value>*.hbm.xml</value>
                    i mean import the all hbm files rather than the application-context files...

                    but <value>classpath*:**/*.hbm.xml</value> is not workin fr my applications

                    Comment

                    Working...
                    X