Announcement Announcement Module
No announcement yet.
Add PackagesToScan to org.springframework....LocalContainerEntityManager FactoryBean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add PackagesToScan to org.springframework....LocalContainerEntityManager FactoryBean

    Hello All -

    Our application is composed of many logical modules. There is a central database that houses all necessary tables required by the entire application. Each module defines a logical JPA entity that it introduces for a business functionality.

    We have a core datasource module that defines the "org.springframework.orm.jpa.LocalContainerEntityM anagerFactoryBean" in the following way:

     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan" value="com.acme.core.model"/>
    What we are looking for is a hook or technique by which each logical module can push its packages to scan (packages that will have JPA entity [ classes annotated with @Entity or @MappedSuperclass ] ) to the LocalContainerEntityManagerFactoryBean . This way we intend to provide a plug-ability feature where based on what modules a customer chooses, our product only has those database tables.

    The customers may also want to add their own module and create their own tables.

    Please let me know.

    Best Regards.

  • #2
    Just off the top of my head, you might think about using a property placeholder for the value: <property name="packagesToScan" value="${}"/> and then specify a property placeholder configured pointing a properties file which contains the key/value pair.

    Or, you might think about ways to use the bean profiles facility in Spring 3.1+.

    But it all depends on how you let the customer choose and how the values get codified into property, bean config files, or whatnot.


    • #3
      Hello -
      Thanks for the reply. How will the property place holder approach allow different modules (assume different Maven modules here) to inject their "packages to scan" (that contain @Entity annotated classes) into the same LocalContainerEntityManagerFactoryBean definition ? Can you please explain.

      Thanks and Best Regards.


      • #4
        I can't really since it's not at all clear as to what your question is. Are you asking about how you would assemble such an application which the customer would then deploy? Or are you thinking that you want to do this in a running application? (You said in the second post: "... assume Maven modules ..."; but I can't "assume" anything.) If it's the former, it seems to be pretty straight forward:

        <bean id="propertyConfigurer" 
        <bean id="sessionFactory" 
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
            <property name="packagesToScan" value="${}" />

        If it's the latter, i.e., forcing a scan of different packages in a running instance, I don't know how to do that.


        • #5
          Thanks for the reply. Let me try to re-explain the issue in case I wasn't clear.

          Let's say I have a product that contains three maven modules : (a) part (b) document (c) core.

          The core module has the definition of the org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean and all other modules depend on it.

          The part module is responsible for define part related classes. [ A part is a soft representation of an actual component in the manufacturing domain, a part for example can be a chasis or a as small as a nut/bolt]. So let's say the part module is responsible to define tables (JPA entities) like "Part", "Assembly" etc. The part module apart from defining the tables also contain other part related functionality that are essential in the manufacturing domain.

          Similarly the document module is responsible to define JPA entities like "MSDOC", "PDF" etc. Similar to part module it contains functionalities around various document tables/classes.

          As a product development team, we would want customers to choose the modules they are interested in. Lets say they only need to now have part functionality for their business. Further, when they buy our solution with only the part module, they may want to customize it and add more tables. They would define their own maven module and want to extend our OOTB part classes and create tables to suit their business need.

          There are precisely two requirements:

          1. Within product development, we would like individual modules to define their classes and inform the single org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean definition (defined in the core module) about the same.
          2. How would end customers when they write class extensions of ootb classes (like extending the part class, and want a corresponding table for their extension ) would inform the single org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean defintion (defined in the core module) about their JPA entities.