lazy-initialization

Thread safe lazy contruction of a singleton in C++

Is there a way to implement a singleton object in C++ that is: Lazily constructed in a thread safe manner (two threads might simultaneously be the first user of the singleton - it should still only be constructed once). Doesn't rely on static variables being constructed beforehand (so the singleton object is itself safe to use during t...

How to solve lazy initialization exception using JPA and Hibernate as provider

I am working on a project for a customer who wants to use lazy initialization. They always get "lazy initialization exception" when mapping classes with the default lazy loading mode. @JoinTable(name = "join_profilo_funzionalita", joinColumns = {@JoinColumn(name = "profilo_id", referencedColumnName = "profilo_id")}, inverseJoinColumn...

hibernate lazy initilization problem

I want to manage a Transaction in my persistence layer, But when I try to fetch the results lazily I get this error: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role Can I use LockMode or any other way to solve this problem? Can a find a Object by its id without any Transaction? ...

Grails and Hibernate's Lazy Initialization Exception

Where are the most common places where you've gotten an org.hibernate.LazyInitializationException in Grails, what was the cause and how did you solve it ? I think this one exception comes up a lot for novice, so if you'd provide more examples, it would be great. ...

Lazy initialization of cache with Spring IBatis

We are moving our legacy implementation to Spring IBatis model. I am kind of stuck in modeling these objects in cleaner way using Spring model Lets say I have two classes [ Both of them are singleton ] DAOImpl implements DAOInterface CacheDAOImpl implements DAOInterface Code snippet showing object initialization in CacheDAOImpl ....

Lazy/multi-stage construction in C++

What's a good existing class/design pattern for multi-stage construction/initialization of an object in C++? I have a class with some data members which should be initialized in different points in the program's flow, so their initialization has to be delayed. For example one argument can be read from a file and another from the network...

Triple checked locking?

So in the meanwhile we know that double-checked-locking as is does not work in C++, at least not in a portable manner. I just realised I have a fragile implementation in a lazy-quadtree that I use for a terrain ray tracer. So I tried to find a way to still use lazy initialization in a safe manner, as I wouldn't like to quadruple memory ...

Could not initialize proxy - No Session again

I get these error log when viewing a page ERROR [TP-Processor11] (LazyInitializationException.java:42) - could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132) at org.hib...

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<std::string> // string array(file names in the path) > tree; but for the serialization the directory tree with the content i need other type: std::map< std::string, // string(path name) std::vector...

Hibernate Lazy initialization exception problem with Gilead in GWT 2.0 integration

Hello, I use GWT 2.0 as UI layer on my project. On server side, I use Hibernate. For example, this is 2 domains entities that I have : public class User { private Collection<Role> roles; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "users", targetEntity = Role.class) public Collection<Role>...

How to create decorator for lazy initialization of a property

I want to create a decorator that works like a property, only it calls the decorated function only once, and on subsequent calls always return the result of the first call. An example: def SomeClass(object): @LazilyInitializedProperty def foo(self): print "Now initializing" return 5 >>> x = SomeClass() >>> x.foo...

NHibernate : pattern for returning fully loaded instances from repositories

Hi all As part of my endless NHibernate-inspired DAL refactoring purgatory, I have started to use the Repository pattern to keep NHibernate at arms length from my UI layer. Here's an example of a Load method from a repository. public StoredWill Load(int id) { StoredWill storedWill; using (ISession session = NHibernateSessionFactory...

lazy function definitions in scala

I've been learning scala and I gotta say that it's a really cool language. I especially like its pattern matching capabilities and function literals but I come from a javascript, ruby background and one of my favorite patterns in those languages is the lazy function and method definition pattern. An example in javascript is var foo = fu...

Why are attributes lazily instantiated?

I've found that attributes in C# seem to be lazily instantiated. [A(123)] class A : Attribute { public A(int b) { GetType().GetCustomAttributes(true); } } In this example, creating a new A instance causes a StackOverflowException, but if I remove the call to GetCustomAttributes(), then execution carries on normally...

Accessors / Getters and Lazy Initialization

I have a question about overriding auto-generated accessor methods. The following would not work (I believe) because each getter references the other getter. Is there a rule that accessor methods should not use other accessor methods, or do you just have to watch out for these situations individually? -(UIImage *) image{ if(image...

Filter Lazily Initialized Hibernate Collection

This might be a super easy answer, since I'm sure it's not uncommon. I see some similar questions, but nothing that seems to describe my problem. I have two objects: a car and person. They're in a many-to-many relationship, i.e. a car can be owned by multiple people, and a person can own multiple cars. Car has a lazily initialized se...

Hibernate -> LazyInitializationException with n:m relation

Hello all! I have a problem with Hibernate and the LazyInitializationException. I searched and find a lot of answers, but I can not use them to solve my problem, because I have to say, I am new to Hibernate. I run JUnit tests, in case of the error this one: @Test public void testAddPerson() { Set<Person> persons = service.getAllPe...

Spring transactions & hibernate: lazy initialization

From what I've read so far I had the understanding that using transactions would be the solution to hibernate's lazy loading problems. The session would be available during the whole transaction in the service layer without further adue. So maybe I misconfigured my transaction management? I'm actually a newb when it comes to spring and ...