Hi,

I have a 'User' entity and 'Role' entity.

User entity:

@Entity
@Table(name="user")
public class User {
@OneToMany(mappedBy="user")
private List<Role> role;
}

I am using following to retrieve roles:

User user = daoService.find(User.class, userId);
daoService.initializeLazyColletion(user.getRole());

In daoService, I have:

@Transactional(readOnly = true)
	public void initializeLazyCollection(Collection<?> collection) {
		if(collection==null) return;		
		PersistenceUnitUtil unitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil();
		if(!unitUtil.isLoaded(collection)){
			collection.iterator().hasNext();
		}
	}

But I am getting following exception:

org.springframework.orm.hibernate4.HibernateSystem Exception: failed to lazily initialize a collection of role: com.test.domain.User.role, could not initialize proxy - no Session; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.domain.User.role, could not initialize proxy - no Session

Please help to fix the issue.

Regards,