On Sat, 27 Sep 2003, Juozas Baliuka wrote: > It must be bug in "SessionHolder".
Hi, Juozas. That code below was actuallly incorrect in my last email, and I have corrected it in-line below: I am actually storing this.ftpSession instead of this.session (line 71 in the original quoted code below). As for the SessionHolder object, I'm using that so that I don't have hundreds of connections to the back-end PostgreSQL database. I've include the code beow -- it should connect to the database if needed and just return a connected net.sf.hibernate.Session object from its method. 01:public class SessionHolder 02:{ 03: private static final boolean DEBUG = true; 04: private static Session session; 05: 06: public static Session getSession() 07: { 08: SessionHolder.connect(); 09: 10: return(SessionHolder.session); 11: } 12: 13: public static void connect() 14: { 15: if (SessionHolder.session == null) 16: { 17: try 18: { 19: SessionFactory sessionFactory = new Configuration() 20: .configure().buildSessionFactory(); 21: SessionHolder.session = sessionFactory.openSession(); 22: } catch (HibernateException e) 23: { 24: if (SessionHolder.DEBUG) e.printStackTrace(); 25: } 26: } else 27: { 28: try 29: { 30: SessionHolder.session.reconnect(); 31: } catch (Exception e) {} 32: } 33: } 34: 35: public static void disconnect() 36: { 37: if (SessionHolder.session != null) 38: { 39: try 40: { 41: SessionHolder.session.close(); 42: SessionHolder.session.disconnect(); 43: } catch (HibernateException e) {} 44: } 45: } 46:} QHat do you think? Is there a better way that I should be doing this without rewriting a heck of a lot of code? I like the idea of having the session establishment self-contained within the SessionHolder object? Does this SessionHolder seem to be the culprit behind the ConcurrentModificationException issues? > > We seem to be having some problems like this in more than one section > > of code. I really don't understand it at all; we suspect some kind of > > JVM bug. Unfortunately, no-one has been able to deliver a testcase > > that will help me reproduce this on my machine. > > I can't really do much, until I can reproduce it. > > P.S. You might also get this if you share a session between two > > threads - but at least some occurrences of this problem do not seem to > > be caused by this.... > > >I'm receiving an Exception in a Hibernate application I've built, and > > >I'm a bit confused as to why this might be happening. The code at > > >where the Exception is thrown is quite simple, and I think this might > > >be a bug in Hibernate itself. I've searched Google for this to no > > >avail, and I'm using the latest recommended Hibernate release as > > >available on the site. > > >The exception I receive has a stacktrace as follows: > > > java.util.ConcurrentModificationException > > > at java.util.AbstractList$Itr.checkForComodification(Unknown Source) > > > at java.util.AbstractList$Itr.remove(Unknown Source) > > > at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2101) > > > at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2061) > > > at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005) > > > at net.sf.hibernate.transaction.JDBCTransaction.commit( > > > JDBCTransaction.java:57 > > > ) > > > at > org.express.ftpsrv.ConnectionHandler.<init>(ConnectionHandler.java:72) > > > at > org.express.ftpsrv.ConnectionListener.accept(ConnectionListener.java:56) > > > at > org.express.ftpsrv.ConnectionListener.main(ConnectionListener.java:19) > > > > > >And the code at ConnectionHandler.java:72 that causes this looks like: > > > > > > 52:this.ftpSession = new FtpSession(); > > > 53: > > > 54:/* ftpSession.setSessionId() does not operate on the unique > > > 55: * 'id' field that is also part of the ftpSession object. > > > 56: */ > > > 57:ftpSession.setSessionId(UniqueGenerator.makeUniqueNumber()); > > > 58: > > > 59:Date currentDate = new Date(); > > > 60:currentDate.setTime(System.currentTimeMillis()); > > > 61:this.ftpSession.setBegTime(currentDate); > > > 62: > > > 63:net.sf.hibernate.Session hSession = null; > > > 64:Transaction transaction = null; > > > 65: > > > 66:try > > > 67:{ > > > 68: hSession = SessionHolder.getSession(); > > > 69: > > > 70: transaction = hSession.beginTransaction(); > > > 71: hSession.save(this.ftpSession); > > > 72: transaction.commit(); > > > 73:} catch (HibernateException e) > > > 74:{ > > > 75: transaction.rollback(); > > > 76:} > > >I'd like to point out that this seems to be an intermittent thing, > > >occurring more often when I instantiate many objects quickly (the > > >quoted lines 52-72, above, are within a cronstructor in the Object). > > >Does anyone have any ideas as to what might be happening or where I > > >might look for additional information in order to track down this > > >bug? Thanks, in advance, for any response on this. -- _ __ __ ___ _| | William R. Lorenz <[EMAIL PROTECTED]> \ V V / '_| | http://www.clevelandlug.net/ ; "Every revolution was \./\./|_| |_| first a thought in one man's mind." - Ralph Waldo Emerson ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel