Questions tagged [lazy-initialization]

Lazy initialization is the tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.

This is typically accomplished by maintaining a flag indicating whether the process has taken place. Each time the desired object is summoned, the flag is tested. If it is ready, it is returned. If not, it is initialized on the spot.

In case of Hibernate, the lazy initialization is made in the proxy (created in place of collection) using the hibernate session from which the object was obtained. If the collection is accessed when the original session is closed (for example, outside a @Transactional scope), the LazyInitializationException is thrown.

To initialize the collection, it is enough to call size() or iterate through all elements.

705 questions
0
votes
1 answer

Lazy Initialization and Templates - Linker error

I've a general problem with my application. I want to use lazy initialization with an Array class I've made, to improve performances; all works fine when all code is in a single *.h file, but compiler returns a linker error when I split the code in…
0
votes
2 answers

Spring and Hibernate: DAO Pattern. How to solve LazyInitializationException

I'm wondering: What is the point of FetchType.LAZY in one(many)-to-many using DAO Pattern? It is basically useless? As soon as you are outside of your DAO (eg. were the actual work is done) you can't fetch the related data as you are not in a…
beginner_
  • 7,230
  • 18
  • 70
  • 127
0
votes
3 answers

How to use double checked lock to init a shared_ptr

(Assuming VC++ 2010: (1) can use /volatile:ms, (2) no std::atomic yet, (3) no thread-safe static variable initialization, (4) no std::call_once) If I have a plain C pointer, I can impl the following double checked lock pattern to avoid the cost of…
0
votes
1 answer

NHibernate - Creating a proxy instance failed

My data model looks like this. public abstract class BasePivotField { public virtual int SystemId { get; set; } public virtual int Version { get; set; } public virtual string FieldName { get; set; } public virtual…
Zuber
  • 577
  • 1
  • 11
  • 29
0
votes
2 answers

LazyInitializationException on eagerly fetched (detached) collection

First some info: I'm using: Spring 3.1.1.RELEASE Hibernate 4.1.5.SP1 JSF 2.0? OpenSessionInViewFilter (org.springframework.orm.hibernate4.support.OpenSessionInViewFilter) PrimeFaces 3.3.1 Lombok 0.11.2 JBoss 7.1.1.Final The short version: When…
siebz0r
  • 18,867
  • 14
  • 64
  • 107
0
votes
2 answers

JPA LazyInitializationException?

I am using jQuery for UI, Struts2 as Action, JPA for Data Access Layer. The issue I am facing is that I am getting LazyInitializationException when I try to retrieve values from the database. I get the stacktrace…
Esh
  • 836
  • 5
  • 16
  • 43
0
votes
1 answer

Cocoa lazy instantiation - best practice

I have a question about the best coding practice for lazy instantiation.  I have a custom class (MainClass) that consitutes the model of my view controller. One of the properties of MainClass is another custom class (SubClass). Now let's say I want…
Jacopo
  • 1,031
  • 2
  • 12
  • 25
0
votes
1 answer

How does instantiating an object in the getter work if the setter is used first?

I'm working through the Stanford lectures, calculator tutorial. http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall In it he suggests a good technique for creating an instance of a model is to alloc/init in the getter with: -…
0
votes
1 answer

Lazy loading doesn't work in @Service class

i am using hibernate 3.5.1-Final, with spring 3.0.5.RELEASE and i am using the following configuration for OpenSessionInViewFilter: hibernateFilter
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
0
votes
1 answer

Spring 3 + LazyInitializationException + OpenSessionInViewFilter

I'm having some problems with Spring 3, with annotations and hibernate. Im trying to execute this in a JSP that will be included in all the others JSPs, its a header. ${pageContext['request'].userPrincipal.principal.notifications} My User pojo have…
0
votes
1 answer

Lazy-initialization enabled CardLayout?

I have a bunch of panels put in a CardLayout where nth panel depends on the state changes caused in (n - 1)th panel. Since with CardLayout, you have to initialize and add all panels beforehand. As such it makes it harder than necessary to manage…
missingfaktor
  • 90,905
  • 62
  • 285
  • 365
-1
votes
1 answer

How to avoid latencies with Python module globals initialization?

I'm trying to optimize the general load time of a web application written in python. My application uses a lot of modules, some of which might or might not be actually needed for a given request. Since page load time is an important factor of the…
Chameleon
  • 9,722
  • 16
  • 65
  • 127
-1
votes
1 answer

Problem with LazyInitializationException and Correct setting ManyToOne

I have 3 object that interfacing each other like that: @Entity public class Room { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column private String name; @OneToMany(mappedBy = "room", fetch =…
Denis Deniben
  • 93
  • 2
  • 10
-1
votes
2 answers

Exception: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role

I am working on a spring boot application. I have developed a functionality that works well without error. However, when I did an integration test with the same code I have the following error: partnerOrderHeaders …
flamant
  • 733
  • 4
  • 15
  • 41
-1
votes
1 answer

LazyAction in C#?

Is there a way in the C# standard API to lazily initialize a block of code? I know Lazy but it is meant to initialize one variable, and requires a function that returns a T. I'd like something that's more like a LazyAction. private _lazyInit =…
edeboursetty
  • 5,669
  • 2
  • 40
  • 67
1 2 3
46
47