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
2 answers

How to find JSF component when there is an exception during rendering?

Environment: JSF 2.0, Seam 2.3, RF 4.3 and PF 5 on JBoss AS 7.2 I have a strange error on two JSF pages. I get a LIE (Lazy Initialization Exception) during the render phase. Error Rendering View[/secure/MyPage.xhtml]:…
Ben
  • 1,922
  • 3
  • 23
  • 37
0
votes
2 answers

Implementing a parametrized thread-safe lazy-init cache using ConcurrentHashMap (without volatile keyword)

The single-check idiom can be used to implement a thread safe-lazy init with (compared to the double-check) the possible drawback of wasting some computation time by multiple concurrent inits. It is Single-check idiom private volatile FieldType…
Christian Fries
  • 16,175
  • 10
  • 56
  • 67
0
votes
2 answers

Spring JPA Lazy Loading - Could Not Initialize Proxy

Below is some code for background: InitiativeProfileQuestion.java: @Entity @Table public class InitiativeProfileQuestion implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(nullable…
0
votes
2 answers

assign value to attribute in other thread

I want to assign value to att = 5 in thread t. In the main thread, I want to check if att has been assigned to 5 yet When I run the void check(), the output is always 3. Why is this? class Program { static int att = 3; static void…
Fish
  • 165
  • 3
  • 16
0
votes
0 answers

Primefaces - dynamic menubar with lazy menuitem loading

I'm moving legacy system to Java-stack. UI of this system have large count of pages with tree hierarchy. For navigation I've used p:menubar. When user logging on menubar is filling. Request all from DB takes much time so I want have lazy…
Gregory
  • 413
  • 5
  • 16
0
votes
2 answers

Spring + Hibernate : LazyInitializationException

I am getting the LazyInitializationException when i try to retrieve information inside a POJO. User.java public class User implements java.io.Serializable { private Set groups = new HashSet(0); public Set getGroups() { return…
Charles Follet
  • 827
  • 1
  • 10
  • 28
0
votes
1 answer

By-request singleton initialization using IoC container in MVVM application

My WPF application uses Caliburn.Micro as MVVM framework, Entity Framework as data access technology. The purpose of the application is to maintain database. There are multiple Views that consist of menu and result datagrid. With menu controls user…
AsValeO
  • 2,859
  • 3
  • 27
  • 64
0
votes
0 answers

Bidirectional Many To Many : how to add a user to a group?

hi I have a @ManyToMany relationship (Users and Groups) in the Group entity I have : @ManyToMany(fetch=FetchType.EAGER , cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable(name = "group_user", joinColumns =…
Yuri
  • 447
  • 3
  • 9
  • 19
0
votes
0 answers

UITableViewCell lazy instantiation cell

I have a UITableView called UserProductViewController and this table view used for two purpose "create and edit" some data. When user click "edit button" open this UserProductViewController edit mode and populate some data within cell from another…
serhat sezer
  • 1,330
  • 1
  • 10
  • 26
0
votes
1 answer

Hibernate session available for queries but lazyInit not working in flow

I am using hibernate 4.3 and SWF 2.4 and encountered a strange behavior in a particular case which leads to a LazyInitializedException. Here is the configuration of the flow :