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.

5918 questions
279
votes
24 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
  • 3,253
  • 5
  • 22
  • 33
252
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.…
KCL
  • 6,733
  • 10
  • 37
  • 43
204
votes
6 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
  • 2,135
  • 2
  • 14
  • 7
194
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
  • 11,317
  • 7
  • 22
  • 12
188
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,521
  • 6
  • 38
  • 60
142
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
  • 37,839
  • 27
  • 91
  • 125
125
votes
10 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
  • 4,367
  • 4
  • 30
  • 28
120
votes
14 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,…
119
votes
12 answers

Generate a routing module while creating a module in angular-cli

I recently started implementing lazy loading in my application. I was wondering whether there is any way to create a routing.module.ts while generating a new module in angular-cli application other than creating it manually?
Saiyaff Farouk
  • 5,103
  • 4
  • 24
  • 38
116
votes
12 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_
  • 45,112
  • 42
  • 145
  • 293
103
votes
9 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
  • 262,204
  • 82
  • 430
  • 521
98
votes
9 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,776
  • 3
  • 23
  • 33
95
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
  • 36,294
  • 34
  • 81
  • 102
94
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
  • 28,822
  • 36
  • 122
  • 195
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
  • 47,929
  • 21
  • 130
  • 148
1
2 3
99 100