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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:01:08+00:00 2026-06-14T08:01:08+00:00

Hi Guys I have a problem with Hibernate when trying to write an array

  • 0

Hi Guys I have a problem with Hibernate when trying to write an array of object to the db. Essential I have an object built from a web service query. This object ‘response’ can have contain a maximum of ten ‘unpaid items’, my problem arises when I try to persist these.

Entity:

@Entity
@Table(name="TABLE_NAME")
public class AccountDetailsRROutput implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id

    private String payeename;

    private String typeunpd;

    private BigDecimal unpdamt;

    @Column(name="TRANSACTION_ID")
    private long transactionId;

    public AccountDetailsRROutput() {
        super();
    }

    // plus all get/sets
}



        //================================================================
        //  Populate the output for the repeating rows table
        //  which can contain a maximum of 10 unpaid items
        //===============================================================
        AccountDetailsRROutput outputRRTable[] = new AccountDetailsRROutput[response.getLineItems().length];

        LOGGER.debug(METHOD_NAME, "Loop through the line items");
        for (int i = 0; i < response.getLineItems().length; i++) {

            //================================================================
            //  Ensure that we have an item so we don't write an empty row
            //================================================================
            if (response.getLineItems()[i].getTypeunpd() == null || response.getLineItems()[i].getTypeunpd() == "") {
                LOGGER.debug(METHOD_NAME, "No unpaid item entry so break out of the the loop");
                break;
            }
            else {
                LOGGER.debug(METHOD_NAME, "We've got an unpaid item so add the details to the DB");

                outputRRTable[i] = new AccountDetailsRROutput();

                outputRRTable[i].setTransactionId(iTransactionID);
                outputRRTable[i].setTypeunpd(response.getLineItems()[i].getTypeunpd());
                outputRRTable[i].setPayeename(response.getLineItems()[i].getPayeeName());
                outputRRTable[i].setUnpdAmt(response.getLineItems()[i].getUnpdAmt());

                //================================================================
                //  Persist the output list DB object
                //================================================================
                LOGGER.debug(METHOD_NAME, "Persist repeating rows table DB object for line item: " + (i+1));
                em_i.persist(outputRRTable[i]);             
            }
        }
    LOGGER.debug(METHOD_NAME, "Finished persisting repeating rows table DB object");
    em_i.flush();

When I try this I get the following error:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

I can get around this my changing emi.persist to emi.merge but it is only writing one element to the db. There can be duplicate records in this table and there is no pk.

  • 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-14T08:01:09+00:00Added an answer on June 14, 2026 at 8:01 am

    You probably have more than one item with the same payeename. Try defining another id (for example an id composed of payeename and transactionID).

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

Sidebar

Related Questions

guys. I have a strange problem. I try to write unit-tests to web-app. I
Ok guys, I have a serious problem with this. I have a static class
hey guys having this really simple problem but cant seem to figure out have
I hope some of you guys can help me with this problem.... I have
Hello guys i have a problem streaming PDF files with php, i'm using this
i have a problem regarding the responseXML of ajax.. I have this code from
Guys have a problem don't know why this is not working, i have file
Hello guys I have this weird problem with Razor Syntax. I have written the
Hello guys i have a problem while trying to use the 'radio' input in
Hey guys I have a problem with MySQL, i'm trying to insert data in

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.