org.hibernate.exception.DataException: could not initialize a collection
When I try to access my collection (List) the following way, I get the following error, even though I do it within same UserTransaction.
:::
EntityAccessorException: org.hibernate.exception.DataException: could not initialize a collection
:::
Caused by: org.hibernate.exception.DataException: could not initialize a collection: 
:::

                        List<Brand> brands = fullTextQuery.getResultList();
			for (Brand b : brands) {

				Iterator<BrandPromoDetails> i2 = b.getBrandPromoDetails()
						.iterator();

				while (i2.hasNext()) {

					BrandPromoDetails bpd = i2.next();

====================================================================================

Whereas, when I change it to as follws, it works. My database is Derby and I am using Hibernate as JPA provider and using Hibernate Search. It would be great if anyone can provide an explanation of this behavior.

List<Brand> brands = fullTextQuery.getResultList();
					
					for (Brand b : brands) {

						@SuppressWarnings("unchecked")
						List<BrandPromoDetails> i2 = em.createQuery("select x from BrandPromoDetails as x where BPDBRAND_ID = ?1")
							.setParameter(1, b.getId())
							.getResultList();
						
						for (BrandPromoDetails bpd : i2) {
org.hibernate.exception.DataException: could not initialize a collection
===

When I try to access my collection (List) the following way, I get the following error, even though I do it within same UserTransaction.
:::
EntityAccessorException: org.hibernate.exception.DataException: could not initialize a collection
:::
Caused by: org.hibernate.exception.DataException: could not initialize a collection: 
:::

                        List<Brand> brands = fullTextQuery.getResultList();
			for (Brand b : brands) {

				Iterator<BrandPromoDetails> i2 = b.getBrandPromoDetails()
						.iterator();

				while (i2.hasNext()) {

					BrandPromoDetails bpd = i2.next();

====================================================================================

Whereas, when I change it to as follws, it works. My database is Derby and I am using Hibernate as JPA provider and using Hibernate Search. It would be great if anyone can provide an explanation of this behavior.

List<Brand> brands = fullTextQuery.getResultList();
					
					for (Brand b : brands) {

						@SuppressWarnings("unchecked")
						List<BrandPromoDetails> i2 = em.createQuery("select x from BrandPromoDetails as x where BPDBRAND_ID = ?1")
							.setParameter(1, b.getId())
							.getResultList();
						
						for (BrandPromoDetails bpd : i2) {