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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:19:15+00:00 2026-06-02T09:19:15+00:00

We’re trying to create JPA mappings atop some read only tables we imported from

  • 0

We’re trying to create JPA mappings atop some read only tables we imported from somebody else’s application. These are multiple 10-billion row tables, so changing their schemas is not an option. We’ve got one table, the Message table, which has an OBJECT_ID value and another table, the DistributionGroup table, which will have many rows of ENTITY_IDs associated with any given OBJECT_ID. The relevant table definitions are as follows:

CREATE TABLE Message (
OBJ_ID varchar(255) NOT NULL,
FileName varchar(255) NOT NULL,
KEY FileName (FileName)) ENGINE=InnoDB;

CREATE TABLE DistributionGroup (
OBJ_ID varchar(255) NOT NULL,
ENTITY_ID varchar(255) NOT NULL,
KEY OBJ_ID (OBJ_ID)) ENGINE=InnoDB;

And the JPA mapping to link these two:

public class MessageRecord {
    private String obj_id;
    private String file;
    private List<DGRecord> list = new ArrayList<DGRecord>();

    @Id
    @Column(name = "OBJ_ID", nullable = false)
    public String getObjID () { return obj_id; }
    public void setObjID (String obj_id) { this.obj_id = obj_id; }
    //... (Similar for FileName)

    @OneToMany
    @JoinColumn(name="OBJ_ID", referencedColumnName="OBJ_ID")
    public List<DGRecord> getDGRecordList() { return list; }
    public void setDGRecordList(List<DGRecord> list) { this.list = list; }
}

public class DGRecord {
    private String obj_id;
    private String entity_id;

    @Id
    @Column(name = "OBJ_ID", nullable = false)
    public String getObjID () { return obj_id; }
    public void setObjID (String obj_id) { this.obj_id = obj_id; }

    @Column(name = "ENTITY_ID", nullable = false)
    public String getEntityId () { return entity_id; }
    public void setEntityId (String entity_id) { this.entity_id = entity_id; }
}

Now, the strange bit happens when we’re running some code to iterate over all of the DGRecords for a given MessageRecord:

MessageRecord record = [obtained earlier];
for (DGRecord dg : record.getDGRecordList()) {
    System.out.println(dg.getEntityId());
    //Do some work with the ENTITY_ID
}

When I run this operation manually against the database, I get what I’m expecting to see:

SELECT * FROM DistributionGroup WHERE OBJ_ID = 'ArbitraryObjID';
OBJ_ID, ENTITY_ID
ArbitraryObjID, EntityID1
ArbitraryObjID, EntityID2
ArbitraryObjID, EntityID3

But the output from the actual code, when record has the same ArbitraryObjID, is:

EntityID1
EntityID1
EntityID1

For any given combination, it’s not returning n different DGRecords, but the same DGRecord values n times, where n is the number of distinct rows returned by manually running the query. I’m not sure if this is relevant or not, but it’s actually looping over the same object n times (evidenced by System.out.println(dg) returning the same package.DistributionGroup@MemoryAddress n times).

What are we doing wrong, and how can we fix it? Keep in mind that table schema changes, or adding a join table, are so costly as to be effectively impossible. But it seems like this should still be able to work given the current setup, since it works well enough as a human.

  • 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-02T09:19:18+00:00Added an answer on June 2, 2026 at 9:19 am

    I think your mapping is wrong,

    try,

    @JoinColumn(name="OBJ_ID", referencedColumnName="ENTITY_ID")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

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.