I think I may know the reason for this breaking, but I wanted to confirm it.
I have the following code (stripped of course):
Code:
Session session = sessionFactory.openSession();
Query query1 = session.getNamedQuery("findAllAccounts");
List someList = query.list();
Transaction tx = session.beginTransaction();
for (Iterator<SomeAccount> it=l.iterator(); it.hasNext(); ) {
SomeAccount account = it.next();
...
}
The above code finds all accounts in a temp table called TEMP_ACCOUNTS. Now what I need to do is check if a value from this temp table is in another table. So I did (inside the for loop above):
Code:
Query query2 = session.getNamedQuery("findAllAccounts2");
List someList2 = query2.list();
So essential I have:
Code:
Session session = sessionFactory.openSession();
Query query1 = session.getNamedQuery("findAllAccounts");
List someList = query.list();
Transaction tx = session.beginTransaction();
for (Iterator<SomeAccount> it=l.iterator(); it.hasNext(); ) {
SomeAccount account = it.next();
...
...
...
Query query2 = session.getNamedQuery("findAllAccounts2");
List someList2 = query2.list();
}
At the last line above, I get the two following errors:
Not able to obtain connection and
Session is closed.
I also tried to create a new Session to get the "findAllAccounts2" query, but it still happens.
Is this because I started the transaction above using the first query and trying to use two different queries within this transaction?
Any direction on this would be great! Thank you.