Category Archives: hibernate

Hibernate exception : cannot simultaneously fetch multiple bags


Exception class : org.hibernate.loader.MultipleBagFetchException
Exception : cannot simultaneously fetch multiple bags


Use @LazyCollection(LazyCollectionOption.FALSE) rather than fetch=FetchType.EAGER
Annotation @LazyCollection(LazyCollectionOption.FALSE) makes that collecion is loaded like with FetchType.EAGER and you can use it on two and more collections.


Initial Code : Works with lazy fetch type

Wrong manipulation : wanna set fetch type to eager

Solution : if you want to force loading collection

hbm2java : specify generated beans package

To specify the package of generated java beans in hbm2java ant task, add jdbcconfiguration tag property “packagename” like following :

hbm2java with ant step by step

– workspace structure:
    + hbm/
        + build.xml
        + hibernate.cfg.xml
        + reveng.xml
        + lib/

– build.xml

– hibernate.cfg.xml

– reveng.xml

then type

your hibernate beans are ready in hbm/generated directory

OneToMany association : hql query returns no results

Problem: hql query retruns null or empty result while sql corresponding query returns some resultsets.
If the target hibernate Java Bean have an EmbeddedId be sure that the AttributeOverrides didn’t include a nullable column attribute.
If so remove these nullable columns attributes from embedded id and put them directly in the bean as Bean variable properties. And this will fix problem

Wrong Id definition

Right Id definition