-1

I'm getting an exception while fetching all the entries present in a table in a DB.

The error that I received is:

org.hibernate.HibernateException: collection is not associated with any session
        at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:678) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:893) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:360) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2554) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]
        at org.hibernate.loader.Loader.doList(Loader.java:2540) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final]

What is shocking to me is that I'm not getting this error during testing but it is coming up in the production environment which is perplexing to me !!

Can somebody here help me in figuring out this strange behaviour ??

Does it have something to do with the size of the table ??

Dimitri
  • 8,122
  • 19
  • 71
  • 128
gautam
  • 197
  • 1
  • 4
  • 17
  • https://stackoverflow.com/questions/18956825/hibernate-collection-is-not-associated-with-any-session?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa] This might help . Make sure session is initialized – Jagruti Apr 06 '18 at 08:44
  • I already want over that answer and got it. But what I wanted to know is that why this exception was not thrown during my local testing !! – gautam Apr 06 '18 at 09:04
  • Please add your code to know more about the issue. – Unknown Apr 06 '18 at 11:00

1 Answers1

-1

Put @Transactional annotation on top of the method.

  • 1
    thanks, I'm seeing this solution suggested by others as well. But what I really wanted to know is the difference in behavior that I'm getting during my Testing environment and a Production environment. Basically, I wanted to know that why this exception was not thrown during my local testing !! – gautam Apr 06 '18 at 08:40