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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:03:29+00:00 2026-05-24T22:03:29+00:00

Hibernate is causing pain merging an object that contains an ordered collection when removing

  • 0

Hibernate is causing pain merging an object that contains an ordered collection when removing an element from the middle of the collection.

Some background: I’m working on a tool that produces CSV reports. In my model I want a report object to have column objects whose order is dictated by a column.orderIndex int value.

The problem comes when I remove a column whose orderIndex isn’t the last in the list. When executing merge(), Hibernate runs the following SQL:

update REPORT_COLUMNS set [...], orderIndex=1 where pkey=2 --This is formerly the 2nd column, and now it's orderIndex is going to collide with the orderIndex of the 1st 
delete from REPORT_COLUMNS where pkey=1 --This is the 1st column, which is being removed

If Hibernate ran the deletion first, there wouldn’t be a problem.

Here’s how the collection is declared:

@OneToMany(fetch = FetchType.EAGER)
@Fetch(value = FetchMode.SUBSELECT)
@OrderBy("orderIndex")
@JoinColumn(name = "report", updatable = true, insertable = true, nullable = false)
@Cascade({ org.hibernate.annotations.CascadeType.DELETE,
    org.hibernate.annotations.CascadeType.DELETE_ORPHAN,
    org.hibernate.annotations.CascadeType.MERGE,
    org.hibernate.annotations.CascadeType.PERSIST,
    org.hibernate.annotations.CascadeType.REMOVE,
    org.hibernate.annotations.CascadeType.SAVE_UPDATE })
public List<ReportColumnImpl> getColumnImpls() {
    return columns;
}

Your help would be much appreciated.

  • 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-24T22:03:30+00:00Added an answer on May 24, 2026 at 10:03 pm

    The easiest solution is to make the constraint deferred, i.e. checked only at the end of the transaction. Oracle supports deferred constraints. Don’t know about your database.

    Else, you might remove the entity to delete, then flush the session, then update the orderIndexes. But you might also have problems if Hibernate tries to update the index of the 4th element before updating the index of the 3rd one.

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

Sidebar

Related Questions

Hibernate has a handful of methods that, one way or another, takes your object
My understanding of Hibernate is that as objects are loaded from the DB they
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have an application that is using Hibernate 3, c3p0, and spring 2.5.6. We
I'm a newbie to Hibernate. I have an Item POJO which contains a Set<String>
I have a program which fetches records from database (using Hibernate) and fills them
In Hibernate, how can I get single row from the table with maximum field
With Hibernate, can you create a composite ID where one of the columns you
Does hibernate HQL queries support using select min, max, count and other sql functions?
I am using Hibernate in a Java application to access my Database and it

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.