Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hey,
Basically my problem is when you have multiple relationships in one entity, and the fetch type of all them is eager then I get the error relating to how hibernate cannot fetch multiple bags at once. But if I switch some to lazy I cannot get access to the collection and it says no session or session is closed. The question is how do I go about getting access to a lazily loaded collection if I must switch some from fetch type eager to lazy?
thanks in advance for your assistance
Hibernate version:
hibernate 3.2
Mapping documents:
RELATIONSHIP 1:(SWITCHING THIS ONE BETWEEN EAGER AND LAZY)
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
RELATIONSHIP 2:
@ManyToOne(fetch=FetchType.EAGER, targetEntity=pack.Region.class)
@JoinColumn(name="REGION_FK", referencedColumnName="Area", nullable=true)
RELATIONSHIP 3:
@OneToOne(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
IF THERE ARE MULTIPLE RELATIONSHIPS WITH FETCH TYPE EAGER, THE ERROR IS:
Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
IF I CHANGE ONE OF THE RELATIONSHIPS TO FETCH TYPE LAZY AND TRY TO ACCESS THE COLLECTION I GET THE FOLLOWING ERROR;
org.hibernate.LazyInitializationException <init>
SEVERE: failed to lazily initialize a collection of role: pack.singles, no session or session was closed
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html