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

  • Home
  • SEARCH
  • 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 969161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:36:05+00:00 2026-05-16T02:36:05+00:00

I am trying to work out how to do the mappings for two different

  • 0

I am trying to work out how to do the mappings for two different projects that share some entities. Since they share only a limited subset of mappings, my first idea was to separate these mappings out into a separate jar. I’m using hibernate annotations to do the mappings (so they’re in the class files, not separate XML).

Both project A and project B depend on this mappings project, which contains only a couple of hibernate mappings. Project A has no mappings of its own but project B does. Whatever I do this always seems to cause problems since if I don’t configure a persistence unit for the mappings project, the mappings are never picked up on. Likewise for project B. If I do configure a persistence unit in the mappings project, project A works, but running a query in project B just gives me (Mapping happens to be the name of the class):

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Mapping is not mapped

I believe this is caused by project B having its own persistence unit, and obviously the two are not being merged. I don’t really want them to either, I’d prefer to only configure one in project A/B and not the jar they depend on. So is there a way to tell hibernate to scan and map the annotations in a dependency jar and add them to the current persistence unit?

  • 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-16T02:36:05+00:00Added an answer on May 16, 2026 at 2:36 am

    I do not know whether you use Spring but i use Spring capabilities To get this behavior by using packagesToScan property among with mappingLocations property as follows

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingLocations">
            <util:list>
                <value>classpath:br/com/ar/model/repository/hql.ar.hbm.xml</value>
                <value>classpath:br/com/br/model/repository/hql.br.hbm.xml</value>
                <value>classpath:br/com/cr/model/repository/hql.cr.hbm.xml</value>
            </util:list>
        </property>
        <property name="packagesToScan">
            <util:list>
                <value>br.com.ar.model.domain</value>
                <value>br.com.br.model.domain</value>
                <value>br.com.cr.model.domain</value>
            </util:list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.validator.autoregister_listeners">false</prop>
            </props>
        </property>
    </bean>
    

    I hope It can be useful

    UPDATE

    According To JPA specification

    The set of managed persistence classes that are managed by a persistence unit is defined by using one or more of the following:

    • One or more object/relational mapping XML files
    • One or more jar files that will be searched for classes
    • An explicit list of the classes
    • The annotated managed persistence classes contained in the root of the persistence unit (unless the exclude-unlisted-classes element is specified)

    As follows

    <persistence>
        <persistence-unit name="titan">
            <!--Explicity list of classes-->
            <class>br.com.ar.model.domain.A</class>
            <class>br.com.ar.model.domain.B</class>
            <!--Set up any jar file by using jar-file element-->
            <!--Its value is a path relative to the JAR file that contains persistence.xml-->
            <jar-file>../lib/customer.jar</jar-file>
            <!--ORM mapping file-->
            <!--It may be present anywhere on the class path-->
            <mapping-file>mapping.xml</mapping-file>
            <properties>
                Properties goes here
            </properties>
        </persistence-unit>
    </persistence>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use a formula that is used to work out
I am trying to work out the best database model for the current setup:
I am trying to work out how to get the value of table cell
I'm trying to work out a way of passing the web current http context
I am trying to work out a code sample to demonstrate the debugging functionality
I am trying to work out the format of a password file which is
I'm still working on groking the F# thing - trying to work out how
I found this in an error log and am trying to work out how
I've been reading about the @font-face rule and trying to work out if it's
I'm trying to work this out. In my project, i have a file called

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.