I've been trying to figure out how to use stateless sessions correctly, but I'm pretty new to Hibernate (3.1.3), MDB's, and JTA. The code below is inside of an MDB which normally has its transactions handled by JTATransactionFactory and JBossTransactionManagerLookup:
Code:
StatelessSession session = sessionFactory.openStatelessSession();
int i = 0;
for (RevenueData data : dataMap.values()) {
session.insert(data);
}
Outside of these few lines, I don't touch transactions or hibernate anywhere else in my code. If I leave the code like this, the data gets inserted but JBoss complains that I didn't close the connection.
If I close the connection myself using session.close(), the data isn't inserted. I don't know why other than I get a message in my log about the XA transaction being rolled back without a reason being quoted. I know this isn't very specific.
I'm assuming that the the reason why everything gets inserted in the first case is because the XA transaction is getting committed. What's the right way to do this? I'd like my connection to be properly closed so my log doesn't get littered with JBoss's complaints, but I can't seem to figure out how to make it happen.
Thanks,
Matt