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 7925897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:29:37+00:00 2026-06-03T18:29:37+00:00

I have to map a large enterprise database schema. As a number of legacy

  • 0

I have to map a large enterprise database schema. As a number of legacy applications are depending on that schema I can’t change it from composite keys to surrogate keys (other than using views with instead-of triggers for ~70% of database objects) which led me to a number of issues I don’t know how to overcome.

  1. How to map tables that have a surrogate (primary, auto-increment) key and a composite unique key to which a number of tables form a many-to-one relation over the surrogate key, and at the same time a number of legacy tables relate over the composite unique?
  2. What to do when several relationships over composite keys share the same component (Naselja: Korisnik/Opcina, Korisnik/Grad)?
    Hibernate tells me I can’t use the same column (Korisnik) twice, unless I add ‘updatable = false, insertable = false’ to the @JoinColumn annotation. Yet when I do that, I get the message that all components of the relation have to have the same settings for insertable and updatable. How do I ever update or insert the second relation then?
  3. Inserting a row into ‘Ulice’ table will give me a error “org.hibernate.AnnotationException: referencedColumnNames(Korisnik, Naselje) of lc.data.hibernate.Ulice.naselja referencing lc.data.hibernate.Naselja not mapped to a single property” unless in ‘Naselja’ table I explicitly add a many-to-one relation to ‘Korisnici’ table in the model, which doesn’t reflect the actual database schema.

From what I’ve read so far JPA doesn’t support relationships to non-primary keys, but people still do it. Also my second problem might be solved with Hibernate 5, but I’m hoping for some good advice what route to take here.

Test model, database scripts and projects:


Database schema MSSQL

MSSQL create database scripts

Java NetBeans example projects

  • 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-06-03T18:29:38+00:00Added an answer on June 3, 2026 at 6:29 pm

    1)
    – map the autoincrementing columns as primary key
    – create classes for the compositeid and map the many-to-one with property-ref

        <component name="compIdProperty" unique="true">
          <property column="naselje" />
          <many-to-one column="korisnik" class="Korisnik"/>
        </component>
    
        <many-to-one name="Naselja" property-ref="compIdProperty">
          <column name="naselje" />
          <column name="korisnik" />
        </many-to-one>
    

    2) AFAIK it is not possible at all using hibernate

    only possible way i see is to map (Grad, Opcina) as properties and manage the association yourself

    3) since this is a legacy schema i would go the compromise of adding the many-to-one and also map the many-to-one to Korisnik in Opcine and Gradovi

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

Sidebar

Related Questions

I have a map that i want to update from a separate thread. Im
I have image map that can I move, but this map will be so
I have a large number of values ranging from 0 - 5463458053. To each
I have a large PDF file that is a floor map for a building.
I have a large non-map image that I want to allow people to view
I have a service that generates a large map through multiple iterations and calculations
I have a large map in vectorgraphics, that I show in my custom view.
In my code I have a map that is used heavily, several thousand times
I have .MAP file which is created from SAS XML mapper. As the name
I have added a large image to the openlayers map I have built. The

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.