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

  • Home
  • SEARCH
  • 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 6785719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:09:40+00:00 2026-05-26T17:09:40+00:00

I’m developing my first EclipseLink J2SE project, and wondering if there’s an efficient way

  • 0

I’m developing my first EclipseLink J2SE project, and wondering if there’s an efficient way to take benefit of the lazy loading even after accessing an object.

Here’s an example to illustrate the problem. suppose we have these 2 entities:

@Entity
public class Group {
long id;

@ManyToOne
Teacher teacher;

//getters & setters
}

@Entity
public class Teacher {
long id;

@OneToMany(mappedBy="teacher", fetch=FetchType.LAZY)
List<Group> groups;

//getters & setters
}

To load the list of teachers (which will be shown on a JTable component), i use a static method from a classe called MyPersistenceManager:

 public static List<Teacher> loadTeachers(){
    Query q=getEM().createQuery("select t from teacher t");
    return (List<Teacher>)q.getResultList();
}

and then the returned list will be referenced as an attribute of the TableModel.

Now suppose we want to load the list of groups correponding to the selected teacher each time the selection changes (there’s no problem here invoking the getter will do the job), and (here is my problem) in order to preserve memory, clean the memory allocated to these groups when the corresponding teacher gets deselected. Is there any way to do that?

Note : my project as mentioned above is a J2SE project, and is meant to be used locally with an embedded data-base (no network of many clients). I’m using a long-lived persistence-context (EM), with the “eclipselink.persistence-context.reference-mode” property set to “WEAK”, and the “shared-cache-mode” set to NONE to disactivate 2nd cache Level (useless in my case). One more thing, you may say that i don’t have to worry about memory issues with the WEAK mode, but the truth is that the WEAK mode doesn’t touch the referenced entities, and in my case the teachers list is referenced so each groups attribute that gets accessed will stay loaded in memory until the application gets closed …

Thanks in Advance
George

  • 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-26T17:09:41+00:00Added an answer on May 26, 2026 at 5:09 pm

    Either memory is a concern, or it is not. Are you running out of memory? If you can have all Teachers in memory, then you can probably have all Groups as well.

    Otherwise, if memory is a concern, then you may want to rethink you design.

    Typically a request or transactional model is used. An EntityManager will only live for the duration of a request or a transaction. At the end of each transaction a new EntityManager is created, or the em is cleared.

    Also, instead of holding onto all instances of a class, the instances are normally queried when required, normally allowing the user to filter the result.

    If you instead want to continue to use a single long lived EntityManager, you could refresh the Students (set refresh on the all students query) to revert the references to their groups.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.