Questions tagged [lazy-loading]

For programming questions about "lazy loading", a design pattern that defers initialization of an object until the point at which it is needed.

Lazy loading is a commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is Eager Loading.

5366 questions
226
votes
12 answers

How can I make a JPA OneToOne relation lazy

In this application we are developing, we noticed that a view was particularly slow. I profiled the view and noticed that there was one query executed by hibernate which took 10 seconds even if there only were two object in the database to fetch.…
Kim L
  • 6,323
  • 9
  • 35
  • 43
218
votes
19 answers

How to fix org.hibernate.LazyInitializationException - could not initialize proxy - no Session

I get the following exception: Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167) at…
Blerta Dhimitri
  • 2,613
  • 4
  • 19
  • 30
188
votes
5 answers

Entity framework linq query Include() multiple children entities

This may be a really elementry question but whats a nice way to include multiple children entities when writing a query that spans THREE levels (or more)? i.e. I have 4 tables: Company, Employee, Employee_Car and Employee_Country Company has a 1:m…
Nathan Liu
  • 1,945
  • 2
  • 12
  • 6
188
votes
14 answers

What is lazy loading in Hibernate?

What is lazy loading in Java? I don't understand the process. Can anybody help me to understand the process of lazy loading?
rocker
  • 10,607
  • 7
  • 20
  • 12
175
votes
10 answers

How to convert a Hibernate proxy to a real entity object

During a Hibernate Session, I am loading some objects and some of them are loaded as proxies due to lazy loading. It's all OK and I don't want to turn lazy loading off. But later I need to send some of the objects (actually one object) to the GWT…
Andrey Minogin
  • 4,222
  • 5
  • 33
  • 55
137
votes
2 answers

JQuery to load Javascript file dynamically

I have a very large javascript file I would like to load only if the user clicks on a certain button. I am using jQuery as my framework. Is there a built-in method or plugin that will help me do this? Some more detail: I have a "Add Comment"…
Jeff Meatball Yang
  • 34,069
  • 26
  • 85
  • 118
115
votes
9 answers

Why is Hibernate Open Session in View considered a bad practice?

And what kind of alternative strategies do you use for avoiding LazyLoadExceptions? I do understand that open session in view has issues with: Layered applications running in different jvm's Transactions are committed only at the end, and most…
HeDinges
  • 3,877
  • 4
  • 28
  • 27
97
votes
8 answers

How to load images dynamically (or lazily) when users scrolls them into view

I've noticed this in numerous "modern" websites (e.g. facebook and google image search) where the images below the fold load only when user scrolls down the page enough to bring them inside the visible viewport region (upon view source, the page…
Salman A
  • 229,425
  • 77
  • 398
  • 489
97
votes
11 answers

Hibernate: best practice to pull all lazy collections

What I have: @Entity public class MyEntity { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) @JoinColumn(name = "myentiy_id") private List
addreses; @OneToMany(cascade = CascadeType.ALL, fetch =…
VB_
  • 43,322
  • 32
  • 111
  • 238
92
votes
13 answers

What is Lazy Loading?

What is Lazy Loading? [Edit after reading a few answers] Why do people use this term so often? Say you just use a ASP/ADO recordset and load it with data or ADO.NET Datasource for a gridview. I guess I should have asked why people use the term Lazy…
Brian Boatright
  • 33,940
  • 33
  • 76
  • 102
91
votes
7 answers

Entity Framework: How to disable lazy loading for specific query?

Is there any way to disable lazy loading for specific query on Entity Framework 6? I want to use it regularly, but sometimes I want to disable it. I'm using virtual properties to lazy load them.
Marco Alves
  • 2,645
  • 3
  • 21
  • 33
87
votes
3 answers

Hibernate lazy-load application design

I tend to use Hibernate in combination with Spring framework and it's declarative transaction demarcation capabilities (e.g., @Transactional). As we all known, hibernate tries to be as non-invasive and as transparent as possible, however this…
Johan Sjöberg
  • 43,692
  • 19
  • 120
  • 139
80
votes
6 answers

Clarifying terminology - What does "hydrating" a JPA or Hibernate entity mean when fetching the entity from the DB

In the context of ORM / Lazy loading of entities, my understanding of the term "Hydration" is as follows: "Hydrating" describes the process of populating some or all of the previously unpopulated attributes of an entity fetched using lazy…
Marty Pitt
  • 26,266
  • 34
  • 115
  • 190
73
votes
2 answers

Hibernate: one-to-one lazy loading, optional = false

I faced the problem that one-to-one lazy loading doesn't work in hibernate. I've already solved it, but still don't properly understand what happens. My code (lazy loading doesn't work here, when I pull Person - Address is also…
VB_
  • 43,322
  • 32
  • 111
  • 238
72
votes
10 answers

Lazy Loading BrowserModule has already been loaded

I am trying to implement lazy loading but getting error as following ** ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module,…
1
2 3
99 100