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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:57:35+00:00 2026-05-25T02:57:35+00:00

I am using ormlite in my android project. I have two classes @DatabaseTable(tableName =

  • 0

I am using ormlite in my android project. I have two classes

@DatabaseTable(tableName = "usershows")
public class UserShow {
    @DatabaseField(id = true)
    private Integer showId;

    @ForeignCollectionField(eager = false)
    private ForeignCollection<Episode> episodes;
    ...
}

@DatabaseTable(tableName = "episodes")
public class Episode {
    @DatabaseField(id = true)
    private Integer episodeId;

    @DatabaseField(foreign = true)
    private UserShow show;
    ...
}

I am saving my UserShows objects like in example

UserShow show = new UserShow();
userShowDao.create(show);

for (Episode e: eps) {
    e.setShow(show);
    episodeDao.create(e); 
} 

UserShow object have a foreign lazy collection episodes, but when I am trying to get all userShows:

shows = userShowsDao().queryForAll();

I am getting all shows objects with collections of episodes. Why this happens? Collection is lazy and I must to get null or something else but no collection of Episode object. How to make this collection really lazy? It may be cool if ORMLite have ability get objects without lazy collections and initialize when it really need. For example as Hibernate.initialize method.

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-25T02:57:36+00:00Added an answer on May 25, 2026 at 2:57 am

    The lazy collections have been well tested and are in use by many others so although there could be bugs with it, it is more likely that you are being tricked by the lazy collection class.

    When each of the UserShow objects is retrieved from the DAO, the episodes will not be null but instead will be set with an instance of LazyForeignCollection. However, no additional queries will be made and there will be no Episode data contained by the collection. If you then make a call to one of the methods on the collection such as userShow.getEpisodes().iterator(), then a separate query is made at that time to allow you to iterate through that show’s episodes. That’s how the lazy collections work.

    If you still think that the lazy collections aren’t working then please show us how you are determining that the shows have episode data. To see what queries are being done where, you can enable Android logging with ORMLite.


    Edit:

    It turns out that @Georgy was using the debugger to investigate the collection. The debugger is most likely calling the same iterator() or toArray() methods which cause the collection queries to be issued at that instant. So there weren’t any episodes in the collection before the debugger asked for them.

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

Sidebar

Related Questions

I'm just trying to setup my Android Project with ORMLite. I'm using Roboguice for
Im using ORMLite in my Android app. I need to persist this class, which
I have a class which I want to persist with OrmLite and it stores
I have a problem by using the ORMlite framework with more than one table
I'm using ormlite for Android and I'm trying to get a multiple column unique-constraint.
I'm using ORMlite to store the date in sqlite in android. I've created a
I have been fiddling with ormlite on android. It's early days and so far
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using JDeveloper , I started developing a set of web pages for a project

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.