I'm using Hibernate 3.2.5 and JSF 2.1.
I have tables accounts, accounts_opportunities and opportunities i.e. a many-to-many relationship set up.
I've mapped all the tables i.e. models.
To save an account, I'm using the following code:
public void saveAccount(Accounts current) {
Transaction tx = session.beginTransaction();
session.save(current);
session.flush();
tx.commit();
}
I get the following error when saving the Accounts object:
failed to lazily initialize a collection of role: models.Accounts.accountsOpportunitieses, no session or session was closed
I'm new to JSF and Hibernate and cannot understand why Hibernate will not save my object!
UPDATE:
I've updated the Accounts model with the following annotation:
@ManyToMany(fetch= FetchType.EAGER)
private Set<AccountsOpportunities> accountsOpportunitieses = new HashSet<AccountsOpportunities>(0);
Data is still not being saved to the database. I now get errors such as session closed.