Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Lazyinitialization exception.

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Lazyinitialization exception.

    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,


  2. #2
    Junior Member
    Join Date
    Aug 2016
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lazyinitialization exception.

    Wiki sol is expert website development Company with a very huge portfolio and so We offer complete web development solutions on national ,,,,,,,,,,,,,,
    WP IVR Plugin| IVR Plugin | IVR For Sale| Nimble Messaging

Similar Threads

  1. Replies: 4
    Last Post: February 20th, 2013, 09:01
  2. Replies: 1
    Last Post: February 6th, 2013, 10:21
  3. Replies: 2
    Last Post: August 30th, 2012, 09:45
  4. Replies: 5
    Last Post: September 5th, 2011, 10:31
  5. Replies: 6
    Last Post: March 25th, 2011, 15:42