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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:25:59+00:00 2026-06-03T13:25:59+00:00

I have a OneToMany connection between tables Result and ResultAux . I can retrieve

  • 0

I have a OneToMany connection between tables Result and ResultAux. I can retrieve a set of ResultAux objects from Result. After that I’m adding some ResultAux objects to set and using merge on each set entry to flush changes into database. Like this:

Set<ResultAux> resultAuxes = result.getResultAuxes();
if (resultAuxes != null) {
    for (ResultAux resultAux : resultAuxes) {
        resultAux = getDaoFactory().getResultAuxDAO().merge(resultAux);
    }
}

For some additional actions i need to know is set entry a new record and will be inserted into table or it’s an old one and (modified or not) will be updated. I noticed that all entries of ResultAux set already have an ID, so i can’t check it for null as i did for other tables. Is there any way to determine such thing (prefferably not involving extra libs)?

EDIT:

<hibernate-mapping>
    <class name="ResultAux" table="RESULT_AUX">
        <id name="id" column="ID">
            <generator class="native" />
        </id>

        <property name="additinalInfoType" column="AITYPE" type="dao.hibernate.utl.AdditinalInfoEnumType" />
        <property name="sorter" column="SORTER" />
        <property name="value1" column="VAL1" />
        <property name="value2" column="VAL2" />

        <many-to-one name="result" column="RESULT_ID" class="Result" />
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="Result" table="RESULT">
        <id name="id" column="ID">
            <generator class="native" />
        </id>

        <property name="questionNumber" column="Q_NUM" />
        <property name="answerNumber" column="A_NUM" />
        <property name="questionGroup" column="Q_GRP" />
        <property name="answerValue" column="A_VAL" />
        <set name="resultAuxes" inverse="true" cascade="all-delete-orphan"
            lazy="false">
            <key column="RESULT_ID" />
            <one-to-many class="ResultAux" />
        </set>
    </class>
</hibernate-mapping>
  • 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-03T13:26:02+00:00Added an answer on June 3, 2026 at 1:26 pm

    Using native as the the primary key generation strategy causes Hibernate to select identity, sequence or hilo as the PK generation strategy depending upon the capabilities of the underlying DB.

    I think for your DB , hibernate selects “sequence” strategy such that you may experience this problem (Records that are not inserted to the DB can have the assigned ID) by the following codes:

    Set<ResultAux> resultAuxes = result.getResultAuxes();
    ResultAux  newResultAux = new ResultAux();
    
    /**
     * As session.save()  requires to return the ID for the saved instance , if  "sequence" strategy is 
     * used , Hibernate will hit the DB  to select the next ID (eg. select some_seq.NEXTVAL) to be used 
     * for the saved instance. So newResultAux  will have an ID after save()  but actually it is not saved to 
     * the DB yet as  saving to the DB  occurs during session.flush()
     */
    session.save(newResultAux);
    resultAuxes.add(newResultAux);
    

    One of the solutions is to add a @Version property to the ResultAux . Then you could check the value of this @Version property to determine whether it is a new record or not as the @Version property for a new record must be NULL

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

Sidebar

Related Questions

I have items that can contain further items, therefore I need a @OneToMany relationship
I have a one way @OneToMany relationship between a Team and Player class. I
I have an entity Bar : @OneToMany(cascade = CascadeType.ALL, mappedBy = bar) private Set<Foo>
I have an table Article that is in relationship with Steps (OneToMany) and Steps
I currently have 4 tables. Product, Category, SubCategory, ProductSubCategory. Category has a OneToMany SubCategory
I use JPA + Hibernate. I have 2 entities (Parent, Child) with OneToMany connection
I have a book entity which has a OneToMany relationship set up to Document
I have a problem with a simple @OneToMany mapping between a parent and a
I have 2 entities: car and wheels (oneToMany) and I want to retrieve my
Say I have an entity like this @Entity Class A{ //fields @Onetomany Set<B> b;

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.