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

Spring, Hibernate and Lazy initialize

I read many post about this problem on SO and didn't find any solution for me. So what I have Error org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException:…
user2483213
  • 321
  • 1
  • 3
  • 15
0
votes
1 answer

spring data lazy loading

I use spring data, jpa and hibernate I have a Advertisement class @Entity public class Advertisement implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(mappedBy="id",…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
0
votes
1 answer

How can System.Lazy access private constructor of T?

I've implemented singleton according to this page using System.Lazy. I wonder, how technically can System.Lazy access constructor of T, when access modificator of constructor is private.
Ondrej
  • 1,209
  • 1
  • 11
  • 21
0
votes
1 answer

Generic lazy-initialization with scala

I didn't want to write alot of boilerplate code, so I decided to write generic method for lazy-init. import java.util._ import concurrent.ConcurrentHashMap object GenericsTest { val cache: ConcurrentHashMap[Long, ConcurrentHashMap[Long, …
Eddie Jamsession
  • 1,006
  • 6
  • 24
0
votes
1 answer

Designated initializer vs lazy initialisation in Objective-C

I'm new to Objective-C. I have a Class that has several properties that need to be initialised to default values. It is not guaranteed that these properties will necessarily be used in the lifetime of an instance. Would you recommend initialising to…
retrodev
  • 2,323
  • 6
  • 24
  • 48
0
votes
1 answer

Accessing an object inside a List (Inception)

I have an object WorkbookMapping, which contains a List of objects SpreadsheetMapping, and each of those objects have another list of objects CellMapping, thus, Inception. When I try to access the List size of the CellMapping List inside the…
Adam Silva
  • 1,013
  • 18
  • 48
0
votes
1 answer

Lazy instantiation in Setter or getter?

Hi when you do lazy instantiation should you do it in the setter or getter? I have heard that you do it in the getter but what if the property is set before it is called for by a getter? Would that mean the property is still nil? Also, if you lazy…
user2076774
  • 405
  • 1
  • 8
  • 21
0
votes
0 answers

C++ RAII, Prototype Design Pattern, and lazy initialization working in tandem

I'm trying my best to adhere to some strict design patterns while developing my current code base, as I am hoping I will be working on it for quite a while to come and I want it to be as flexible and clean as possible. However, in trying to combine…
Gazoo
  • 215
  • 4
  • 14
0
votes
0 answers

Will javascript structure makes an ajax request faster?

Lets say I solve a common ajax problem (looping ajax and solving the async problem{not sure if this is a problem}). Like this. var users = [{username: 'foo', email : 'foo@email'}, {username: 'bar', email : 'bar@email'},] function iterate() { …
Joey Hipolito
  • 3,108
  • 11
  • 44
  • 83
0
votes
1 answer

Running scheduled method with lazy-init option of the class it belongs to

I have a class 'ABC' which gets initialized lazily at the time of context-up depending on some external parameters. Class has one method 'test' with @Scheduled annotation which does some scheduled activity. public class ABC{ …
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85
0
votes
1 answer

Lazy type registration using Unity App bloc

Is it possible to registe the type (container.RegisterType()) in such a way that the type gets registered in container when the type is asked for using container.Resolve<> Method. I measn someting like Lazy Registration? …
sudhirk
  • 423
  • 1
  • 5
  • 12
0
votes
2 answers

Hibernate Criteria get associated object for collection

I have the following Hibernate entities: User, Role and Team. There is also the UserTeamRole entity which is basically a connection between a User, his Role and the Team he is in: @Entity @Table(name = "user_team_role") public class UserTeamRole { …
AndaP
  • 1,308
  • 8
  • 23
  • 40
0
votes
2 answers

Lazily instantiate a rarely used a view model?

My main view model (mainViewModel) contains an inner view model (innerViewModel) that is bound to it's view (innerView) using a DataTemplate. In my mainView I have a ContentPresenter that has it's Content property bound to the innerViewModel and…
Coder1095
  • 828
  • 10
  • 25
0
votes
2 answers

Grails using spring security in SecurityFilters

In my grails application in production server I got some issues. In securityFilters I'm injecting springSecurityService and at some point I'm asking something like if(springSecurityService?.currentUser?.client){ ... } But system throws an error as…
ufucuk
  • 475
  • 9
  • 21