I have mapped the BLOB columns to byte[] as per the blog(
http://hansonchar.blogspot.com/2005/06/oracle-blob-mapped-to-byte-in.html) and deployed in a JTA environment.
Now this peace of code.
Code:
Query query = getSession().
getNamedQuery("LetterTemplate").
setLong("letterID", letterTemplateSearchCriteria.getLetterID());
template = (LetterTemplateDO) query.uniqueResult();
/* Setting the blog content into the byte array of same object */
if (null != template && null != template.getLetterTemplate()) {
template.setLetterTemplateStream(
template.getLetterTemplate().getBytes(1,
(int) (template.getLetterTemplate().length())));
}
is throwing a
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.sql.BLOB.getDBAccess(BLOB.java:955)
at oracle.sql.BLOB.length(BLOB.java:155)at this line
template.setLetterTemplateStream(
template.getLetterTemplate().getBytes(1,
(int) (template.getLetterTemplate().length())));
Did some google on this error and some analysis of the log file got to know,
1. The JDBC connection will be closed as soon as the Query is executed (
http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#configuration-optional, find hibernate.connection.release_mode), which will result in connection closed error.
2. Log from the application:
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.loader.Loader - result row: EntityKey[ca.medavie.systemsetup.data.domain.LetterTemplateDO#103]
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 4, globally: 4)
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.ConnectionManager - aggressively releasing JDBC connection
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 3, globally: 3) (open ResultSets: 0, globally: 0)]
18:41:22.729 [httpSSLWorkerThread-8080-1] DEBUG o.h.e.StatefulPersistenceContext - initializing non-lazy collections
18:41:22.729 [httpSSLWorkerThread-8080-1] ERROR c.m.g.c.d.Impl - Error occured during retrievalAlso somehow (i'm wondering) it used to work previosuly. This this is unpredictable and causing lot of problem.
I'm requesting help to make this code working in JTA environment(Glass fish, Oracle) with consistent behavior ? Please suggest some options.
Thanks for the help in advance.