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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:27:05+00:00 2026-06-06T15:27:05+00:00

I have a situation where lazy-loading is not occurring when I want it to

  • 0

I have a situation where lazy-loading is not occurring when I want it to in a one-to-many.
Obviously, I am new to this. Why won’t the SongComposers get fetched when I call s.getSongComposers()?

Here is my DAO class:

public class SongDAOImpl implements SongDAO {

    @PersistenceContext
    private EntityManager em;

    @Override
    @SuppressWarnings(value = { "unchecked" })
    public List<Song> getAllSongsOnAlbum(int albumID) {
        Query q = em.createQuery("SELECT s FROM Song s WHERE s.album.albumID  = :albumid ORDER BY s.songName");
        q.setParameter("albumid", albumID);
        List<Song> list = (List<Song>) q.getResultList();
        for (Song s: list) {
            s.getSongComposers();
        }
        return list;
    }

}

Here is my Song entity:

@Entity
@Table(name="songs")
public class Song {

    @Id
    @GeneratedValue
    @Column(name="SongID")
    private int songID;

    @Column(name="SongName")
    private String songName;

    @Column(name="Length")
    private int length;

    @ManyToOne
    @JoinColumn(name="AlbumID", referencedColumnName="AlbumID")
    private Album album;

    @OneToMany(mappedBy="song")
    private List<SongComposer> songComposers;


      .... all getters/setters ......
      }

Here is my SongComposer entity:

@Entity
@Table(name="song_composer")
public class SongComposer {


    @Id
    @GeneratedValue
    @Column(name="SongComposerID")
    private int songComposerID;


    @ManyToOne
    @JoinColumn(name="SongID", referencedColumnName="SongID")
    private Song song;


    @ManyToOne
    @JoinColumn(name="ComposerID", referencedColumnName="ComposerID")
    private Composer composer;


         ..... getters/setters .......

}
  • 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-06T15:27:06+00:00Added an answer on June 6, 2026 at 3:27 pm

    You have to do it explicitly. Try this query:

    SELECT DISTINCT s FROM Song s JOIN FETCH s.songComposers WHERE s.album.albumID  = :albumid ORDER BY s.songName"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I'm lazy loading images from the www. It's a
i have situation like this: class IData { virtual void get() = 0; virtual
I have the following situation: One Destination can have Many Aliases Logically : I
let's get some different points of view about this situation I have. I'm creating
I have situation where I need to change the order of the columns/adding new
I have situation like this: user submits form with action='/pay' in '/pay' I have
I have an web application that uses NHibernate as ORM. I enable lazy loading
I have situation to extend the Enumerable class in c# to add the new
I have an object wich has a lazy-loading relationship . After I loaded the
This should be relatively simple, here is my situation; I have copied the trunk

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.