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

Single- and double-check lazy initialization

I can't understand piece of code in Item 71 in 'Effective Java' about the Double-check idiom and the single-check idiom for lazy initialization of instance fields: Double-check idiom private volatile FieldType field; FieldType getField() { …
Dmytro
  • 1,850
  • 3
  • 14
  • 20
0
votes
3 answers

Lazy Initialization - Invalid arguments

I am coding a MVC 5 internet application, and am having some trouble with initializing a Lazy object. Here is my code: public Lazy> accounts; public IGenericRepository accountsNotLazy; I am wanting to…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
1 answer

How to use lazily instantiated property within another lazy instantiation

Xcode does not see my lazily instantiated property components within lazy instantiation of weekdayLetters. How can I resolve this? DaysViewController.Type does not have a member named 'components' lazy var weekdayLetters: [String] = { for index…
Martin Koles
  • 5,177
  • 8
  • 39
  • 59
0
votes
1 answer

How to avoid lazy vals when using cross dependent traits in cake pattern without additional traits

Suppose we have scala> trait A { val y: Int; val x = 1; val y2 = y + 1 } scala> trait B { val y: Int = 1; val x: Int; val x2 = x + 1 } scala> class C extends A with B Then both y2 and x2 should end up with value 2 in C. Now if we mixin A then B…
samthebest
  • 30,803
  • 25
  • 102
  • 142
0
votes
1 answer

Can't add Lazy initialized object to Generic List

I have generic list: class BooksRegister { private T[] Register; public int Count { get; set; } public BooksRegister() { Register = new T[100]; Count = 0; } public…
0
votes
2 answers

Hibernate LazyInitializingException

For example, I have 2 classes. The first @Entity @Table(name = "employee") public class Employee implements Serializable{ @ManyToOne @JoinColumn(name = "office_address_id") private Address address; //setters and getters } And the…
somebody
  • 1,077
  • 5
  • 14
  • 32
0
votes
4 answers

get List object HQL

I have a mother Class (SchemaBase) containing a list of CubeBase so i wannt to recuperate that list of CubeBase containing the id of SchemaBase: public ListlistCube(){ …
0
votes
0 answers

LazyInitializationException despite of OpenSessionInViewFilter

I develop webapp using Spring 4, Hibernate 4 and JSF 2.2. I'm trying to use OpenSessionInViewFilter to avoid LazyInitializationException but I fail. I have class Consultant with such field: @OneToMany(fetch = FetchType.LAZY, mappedBy =…
Paul
  • 1,917
  • 4
  • 17
  • 16
0
votes
2 answers

boost.serialization and lazy initialization

i need to serialize directory tree. i have no trouble with this type: std::map< std::string, // string(path name) std::vector // string array(file names in the path) > tree; but for the serialization the directory tree with the…
niXman
  • 1,698
  • 3
  • 16
  • 40
0
votes
1 answer

How to Fix Lazy initialisation exception for this

Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.softforge.domain.UserAcc.testAccList, no session or session was closed /* * To change this license…
FullMetal
  • 38
  • 1
  • 6
0
votes
1 answer

hibernate lazy error but I don't want those data

I have POJO with couple of strings/numbers/... and I want to get only this pojo, without any sub-POJOs in lists/maps/sets that could be attached by hibernate. If I execute query to get first pojo, exception is thrown when someone touches those…
Matjaz
  • 468
  • 5
  • 21
0
votes
1 answer

onShow event fires unnecessarily during each page reloading

I have an issue with making a menu in my project using Primefaces. Actually, this menu will get me a possibility to show some small dialogs with settings for the workspace (by clicking on menu items). Each dialog should have data lazy loading from…
Maxxon
  • 31
  • 2
  • 8
0
votes
0 answers

LazyInitializationException in Spring/Hibernate

I have a Spring app , many-to-many relationship between Order and Product with intermediary table ProductOrder. If I save the ProductOrder directly to the db, it works fine, but I don't think that's the correct way, so I use the code below to add an…
Natasha
  • 1,470
  • 5
  • 18
  • 24
0
votes
0 answers

MVC LazyInitializer Error Handling

I want to have an error Page if My Aplication cannot connect to Database. But for now I have sth like this: Then If I step over I have an error in Layout where I check if IsAuthenticated it also shows an error in
  • @if…
  • 0
    votes
    1 answer

    Hibernate LazyInitializationException with Spring MVC

    Problem Using Kolorbot's Spring MVC 4 Quickstart archetype I created an entity, a repository and a service class which is accessed by a controller method. In my entity I have a ManyToOne relationship to another entity by fetching it lazily. In my…
    Dennis
    • 1,805
    • 14
    • 17