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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:07:29+00:00 2026-06-13T07:07:29+00:00

I found in some old code strange thing (at least for me). The field

  • 0

I found in some old code strange thing (at least for me).

The field which is annotated @ManyToOne is also annotated with @BatchSize.

I always thought that @BatchSize annotation only affects when annotated at class level or on a collection (@OneToMany) and affects pre-fetching when iterating.

But maybe I am wrong and annotating @ManyToOne with @BatchSize affects something. I can’t find the answer in the documentation.

Does annotating @ManyToOne with @BatchSize have sense?

  • 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-13T07:07:30+00:00Added an answer on June 13, 2026 at 7:07 am

    @ManyToOne associated with @BatchSize could make sense only if the corresponding field is marked as lazy (lazy=true).

    Indeed, if the field is not lazy, it’s by definition already loaded since the enclosing entity is loaded, so the problem of database calls doesn’t apply.

    Imagine a Person class who has a collection of ShoesPair element (ShoesPair.class) and within this one is present an owner field marked as lazy (since optional and not really bringing an important information when retrieving a specific pair of shoes).

    One wants to iterate through 25 pair of shoes (25 ShoesPair objects) in order to retrieve their owner.

    If the owner field (corresponding to one person) is only annotated with @ManyToOne, there would be 25 select to database.

    However, if annoted with @BatchSize(size=5), there would be merely 5 calls and so increasing performance.

    From the Hibernate documentation, it is precised that batch size does not only apply with collections:

    You can also enable batch fetching of collections.

    Hibenate mentions especially @OneToMany cases, because these one are applied with fields that are in 90% of cases marked as lazy.

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

Sidebar

Related Questions

I found some old code which I'm not sure I understand completely. The folowing
I found some old code written by NoBugz ( Hans Passant ) which, if
I found some old Python code that was doing something like: if type(var) is
I have some old javascript code from around 2000-2002 which (surprisingly) still works in
I am looking through some old code and found a piece that i cant'
I'm working on some old code and I found that I used to use
I've found myself running back through some old 3.5 framework legacy code, and found
I'm going through some old code and found the following: public class MyClass implements
This morning I was looking over some old code I found somewhere (and used
I was looking into some old code in my product and i found following

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.