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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:52:53+00:00 2026-05-28T06:52:53+00:00

I have roughly 100,000 Objects that I want to insert into the database. I

  • 0

I have roughly 100,000 Objects that I want to insert into the database. I would like to leverage Spring/Hibernate and create List<MyPojo> and use session.saveOrUpdate() to perform the insert.

However, the MyPojo object contains about 25 foreign keys. To perform that many lookups by Id to get the actual referenced object would be extremely inefficient.

Therefore I’d like to just use the foreign key ids (the same way that it would be stored in the database) rather than load every object.

Outside of running native queries, is there another solution to do this?

Thanks!

  • 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-28T06:52:54+00:00Added an answer on May 28, 2026 at 6:52 am

    You can do this by mapping the foreign key and the object, but marking the object as lazy and not “updatable” and not “insertable”.

    Here is the object, but not used for writing the values.

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MY_POJO_FK", insertable = false, updatable = false)
    private MyPojo myPojo;
    

    Below is the foreign key mapped normally

    @Column(name = "MY_POJO_FK")
    private Long myPojoFK;
    

    The downside of this approach is you have to update the foreign objects individually (no cascading), but the advantage is you will not load the foreign objects until you need them.

    If you are only mapping this to write data, you don’t need to worry about mapping the object at all.

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

Sidebar

Related Questions

I have a structure that roughly looks like this: List<ProductLine> -> ID Name ...
I have a class that roughly looks like this: public class ViewModel { public
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have a an XSD that looks like this (roughly) <xs:schema id=Appointment targetNamespace=http://tempuri.org/Record.xsd elementFormDefault=qualified
I have a table with roughly 100.000 blog postings, linked to a table with
I have an array of doubles, roughly 200,000 rows by 100 columns, and I'm
I have roughly 12 computers that each have the same script on them. This
/* Suppose I have a multi-line comment with hard line-breaks * that are roughly
On my C# asp.net webform I have a search page that has roughly 20
I feel dumb right now. I got to update 100.000 rows on a database

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.