Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6971347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:49:42+00:00 2026-05-27T16:49:42+00:00

I have the following structure: common-module Contains the common module related , services and

  • 0

I have the following structure:

common-module

  • Contains the common module related , services and persistence api
  • Contains a common persistence context test-common-persistence-context.xml.

search-module (depends on Common Module)

  • Contains the search module related model beans(marked with JPA Entity annotations), services and persistence api
  • Contains search module related spring context files

booking-module (depends on Common Module)
– Contains the booking module related model beans(marked with JPA Entity annotations), services and persistence api
– Contains booking module related spring context files

In the common-module I have test-common-persistence-context.xml.For the sessionFactory bean having type
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean I need to set the property “packagesToScan” value to the packages in which JPA Entity annotation marked model beans are present.Without it, I get the exception Unknown entity: MY_ENTITY_NAME

Common Module: test-common-persistence-context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

            <!-- Property Place Holder -->
            <context:property-placeholder location="classpath:test-common-persistence-bundle.properties" />

            <!-- Data Source -->        
            <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName" value="${test.db.driverClassName}"/>
                <property name="url" value="${test.db.jdbc.url}"/>
                <property name="username" value="${test.db.username}"/>
                <property name="password" value="${test.db.password}"/>
            </bean>

            <!--
                Hibernate Configuration
            --> 
            <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
                <property name="dataSource" ref="dataSource"/>
                <property name="packagesToScan" value="${test.packages.to.scan.jpa.annotations}"/>
                <property name="hibernateProperties">
                    <value>
                        <!-- SQL dialect -->
                        hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
                        hibernate.hbm2ddl.auto=update
                    </value>
                </property>      
            </bean>

            <!-- Transaction Manager -->
            <bean id="txManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory"/>
            </bean>

            <tx:annotation-driven transaction-manager="txManager"/>

    </beans>

In my common-module there are no JPA entities so I don’t have any package to scan so I keep the “packagesToScan” property value empty

However I need to use the same persistence context in my search-module and booking-module tests (SearchPersistenceTestBase.java) so that the JPA entities in the respective module gets detected.

Search Module: SearchPersistenceTestBase.java

    @Ignore
    @ContextConfiguration(locations = {
            "classpath:test-common-persistence-context.xml",
            "classpath:test-search-spring-context.xml"})
    @TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
    public class SearchPersistenceTestBase extends AbstractTransactionalJUnit4SpringContextTests {

    }

Can anybody please guide me in how to achieve this desired behavior with the set up I have shown above?

** Approach I tried **

I thought of using an additional java.lang.String type bean whose value is set from a properties file

 <bean id="entityPackagesToScan" class="java.lang.String">
     <constructor-arg value="${test.packages.to.scan.jpa.annotations}" />
  </bean>

where test.packages.to.scan.jpa.annotations is defined as empty in test-common-persistence-bundle.properties

And then I override the bean definition in test-search-spring-context.xml

test-search-spring-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <!-- Property Place Holder -->
        <context:property-placeholder location="classpath:test-search-bundle.properties" />

        .. context-component scan elements here

        <bean id="entityPackagesToScan" class="java.lang.String">
            <constructor-arg value="${test.packages.to.scan.jpa.annotations}" />
        </bean>
</beans>

where test.packages.to.scan.jpa.annotations is defined as “com.search.model” in test-search-bundle.properties

But this didn’t worked and I got the exception Unknown entity: MY_ENTITY_NAME

Thanks,
Jignesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:49:42+00:00Added an answer on May 27, 2026 at 4:49 pm

    Ok I got this resolved. org.springframework.beans.factory.config.PropertyOverrideConfigurer is what was needed.I am posting here the solution for reference in case anybody faces similar problem like I mentioned in first post:

    Common Module: test-common-persistence-context.xml

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
                <!-- Property Place Holder -->
                <context:property-placeholder location="classpath:test-common-persistence-bundle.properties" />
    
                <!-- Data Source -->        
                <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                    <property name="driverClassName" value="${test.db.driverClassName}"/>
                    <property name="url" value="${test.db.jdbc.url}"/>
                    <property name="username" value="${test.db.username}"/>
                    <property name="password" value="${test.db.password}"/>
                </bean>
    
                <!--
                    Hibernate Configuration
                --> 
                <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
                    <property name="dataSource" ref="dataSource"/>
                    <!-- Not setting "packagesToScan" property here.As common-module doesn't contain any JPA entities -->
                    <property name="hibernateProperties">
                        <value>
                            <!-- SQL dialect -->
                            hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
                            hibernate.hbm2ddl.auto=update
                        </value>
                    </property>      
                </bean>
    
                <!-- Transaction Manager -->
                <bean id="txManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                    <property name="sessionFactory" ref="sessionFactory"/>
                </bean>
    
                <tx:annotation-driven transaction-manager="txManager"/>
    
        </beans>
    

    Search Module: test-search-spring-context.xml

     <?xml version="1.0" encoding="UTF-8"?>
       <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
            .. context-component scan elements here
    
            <!-- 
            Holds the overridden value for the org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
            (id="sessionFactory" bean in test-common-persistence-context.xml (common module))
            "packagesToScan" property value set for search module.
    
            E.g. sessionFactory.packagesToScan=com.search.model.persistent 
            -->
        <context:property-override location="classpath:test-search-bundle.properties"/>
    </beans>
    

    Search module: test-search-bundle.properties

         ########### Packages to scan JPA annotation
         # This is used by org.springframework.beans.factory.config.PropertyOverrideConfigurer
         # to override   org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean's
         # packagesToScan property value which is different for each module i.e. 
         # common-module does not contain any persistent models
         # search-module and booking-module contains persistent models
         # which needs to be scanned by Spring container to detect them as JPA entities
    
         sessionFactory.packagesToScan=com.search.model.persistent
    

    Thanks,
    Jignesh

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following object structure, deseralized from XML (WS): <ns2:Category> <ns2:CategoryId>800003</ns2:CategoryId> <ns2:CategoryName>Name1</ns2:CategoryName> <ns2:Categories> <ns2:Category>
I have the following directory structure: modules/ api/ controllers/ ApiController.php InventoryController.php OtherController.php The init()
I have a (custom) php framework that contains following structure: app |-classes |-settings core
I have to following XML document structure: <option_set id=1> <option>Yes</option> <option>No</option> <option>Maybe</option> </option_set> <question
I have following structure with example data: id season_id title 1 1 Intro 2
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following structure: class Base { } class Child : Base {
I have the following structure public class MyClass : MyBaseClass<System.Int32> { } In a
I have the following structure: <div id=container> <div id=someid1 style=float:right></div> <div id=someid2 style=float:right></div> <div
suppose you have the following structure: #include <windows.h> // BOOL is here. #include <stdio.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.