This is the first thing I wanted to check;
Quote:
You will need to do some better session validity testing than what exists now (none really) or even just always grab a new session (bad for performance). And you shouldn't need to grab a new session factory, just a new session from that session factory.
I did a first test and added in the HibernateUtil class in the getSession() method a method call session.isdirty(), if the session isn't valid anymore, this throws an exception (unfortunately it isn't really reliable). In the catch block I wrote the following line: session = sessionfactory.openSession().
Some strange things happen. I tested the new code with a string that is too long for the database field, what happens is, that once a "data too long error" occurs, it doesn't matter how short your following log messages are, they have always the length of the message that was too long and therefore every following message throws again an error. :-(
Where does this error come from? New session objects are created for every message.
Another point is, that even when I test if the session is valid before starting a transaction, there is no guaranty, that it remains valid during it. Imagine the following scenario:
- get session
- start transaction
- do buisness database communication
- log some event (!!! logging fails, and throws hibernate exception !!!)
- do some more database communication
- commit transaction (throws exception)
Quote:
It would be a good idea to take logging messages and check their length against the configuration and either truncate the messages that are too long or split the logging messages accross multiple log entries. In either case you may also want to increase the log message db field size and could even make it a CLOB if the performance of that doesn't bother you.
It is not really that special error that bothers me, I came accross it accidently, it's more the fact that logging affects my whole application flow. I think I could easily avoid this kind of error. But even if I decide, that I don't care about handling these exceptions there is still the transaction problem:
Quote:
You also need to be vary careful about transactional boundaries.
I really have no good idea how to solve this with only one shared session object. The only idea I have, would be to remove the line tx.commit() in the hibernate appender and all transaction handling is made in the actual application code.
So far my results. Thank you for your reply!