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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:13:51+00:00 2026-05-14T05:13:51+00:00

table A and B need to have 1:M relationship a and b are added

  • 0

table A and B need to have 1:M relationship

a and b are added during application runtime, so A created, then say
4 B’s created. Each B instance has to come in order, so that I could later
extract them in the same order as I added them.

The app will be a web-app running on Tomcat, so 10 instances may work simultaneously.

So my question are:

1) How to preserve inserting order, so that I could extract B instances that A references in the
same order as I persisted them. That’s tricky, because we add to a Collection and then it gets saved (am I right?). So, it depends on how Hibernate saves it, what if it changes the order in what we added instances? I’ve seen something like LIST instead of SET when describing relationships, is that what I need?

2) How to add a 3-rd column to B so that I could differentiate the instances, something like
SEX(M,F,U) in B table. Do I need a special table, or there’s and easy way to describe constants in Hibernate. What do you recommend?

3) Talking about concurrency, what methods do you recommend to use? There should be no collisions
in the db and as you see, there might easily be some if rows are not inserted (PK added) right
where it is invoked without delays ?

  • 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-14T05:13:51+00:00Added an answer on May 14, 2026 at 5:13 am

    How to preserve inserting order, so that I could extract B instances that A references in the same order as I persisted them. (…)

    Use an ordered collection like a List. Note that Lists can be mapped in two different ways:

    • as ordered lists, the order is not materialized in the database
    • as indexed lists, the order is materialized in the database

    Refer to the section 2.2.5.3.4. Indexed collections (List, Map) for the details.

    How to add a 3-rd column to B so that I could differentiate the instances, something like SEX(M,F,U) in B table. Do I need a special table, or there’s and easy way to describe constants in Hibernate. What do you recommend?

    Use an enum on B and map with @Enumerated. See this previous answer.

    Talking about concurrency, what methods do you recommend to use? There should be no collisions in the db and as you see, there might easily be some if rows are not inserted (PK added) right where it is invoked without delays ?

    Hmm… Use transactions and the locking strategy that suits your needs (but to be honest, I’m not sure I understood the question).

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

Sidebar

Related Questions

Say I have a customer table with 1:0..1 relationship with another table, I would
I have a table that's been created by a module. I need to include
I have need to select a number of 'master' rows from a table, also
I have the following need I have a logging table which logs som leads
I have a large database table that I need to display on a Windows
I have a database two tables and a linking table that I need a
I have a query that does what i want joining table but i need
I need a select from table which does not have column that tells when
I need to style a table to have rounded corners. I'm just looking at
I have a table with string values that need to matched individually to a

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.