Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 32C21CA21 for ; Fri, 1 Jun 2012 18:00:25 +0000 (UTC) Received: (qmail 36593 invoked by uid 500); 1 Jun 2012 18:00:25 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 36570 invoked by uid 500); 1 Jun 2012 18:00:25 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 36562 invoked by uid 99); 1 Jun 2012 18:00:25 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 18:00:25 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id AE30A1402B8 for ; Fri, 1 Jun 2012 18:00:24 +0000 (UTC) Date: Fri, 1 Jun 2012 18:00:24 +0000 (UTC) From: "Heath Thomann (JIRA)" To: dev@openjpa.apache.org Message-ID: <844320252.27529.1338573624715.JavaMail.jiratomcat@issues-vm> In-Reply-To: <791265866.33416.1319834852300.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Resolved] (OPENJPA-2067) A 'length' of '-1' passed to PreparedStatement.setBinaryStream can cause an exception on some, but not all, JDBC drivers. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-2067?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Heath Thomann resolved OPENJPA-2067. ------------------------------------ Resolution: Fixed Fix Version/s: 2.2.1 2.3.0 2.1.2 2.0.2 1.2.3 > A 'length' of '-1' passed to PreparedStatement.setBinaryStream can cause an exception on some, but not all, JDBC drivers. > ------------------------------------------------------------------------------------------------------------------------- > > Key: OPENJPA-2067 > URL: https://issues.apache.org/jira/browse/OPENJPA-2067 > Project: OpenJPA > Issue Type: Bug > Components: jdbc, sql > Affects Versions: 1.2.3, 2.0.2, 2.1.2, 2.2.0 > Reporter: Heath Thomann > Assignee: Heath Thomann > Priority: Minor > Fix For: 1.2.3, 2.0.2, 2.1.2, 2.3.0, 2.2.1 > > > I recently worked on an issue where a JDBC driver is throwing an exception when attempting to persists an InputStream: > Caused by: org.apache.openjpa.persistence.PersistenceException: String or buffer length not valid. > FailedObject: prepstmnt 1608671202 UPDATE PMYPJRK SET lastModificationDate = ?, fileLength = ?, fileName = ?, inputStream = ? WHERE id = ? [org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement] > ......... > Caused by: java.sql.SQLException: String or buffer length not valid. > at com.ibm.as400.access.JDError.throwSQLException(JDError.java:415) > at com.ibm.as400.access.AS400JDBCPreparedStatement.setBinaryStream(AS400JDBCPreparedStatement.java:2098) > at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.setBinaryStream(WSJdbcPreparedStatement.java:1444) > at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.setBinaryStream(DelegatingPreparedStatement.java:340) > at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.setBinaryStream(LoggingConnectionDecorator.java:1104) > at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.setBinaryStream(DelegatingPreparedStatement.java:340) > at org.apache.openjpa.jdbc.sql.DBDictionary.setBinaryStream(DBDictionary.java:875) > at org.apache.openjpa.jdbc.sql.DBDictionary.setTyped(DBDictionary.java:1244) > at org.apache.openjpa.jdbc.sql.RowImpl.flush(RowImpl.java:890) > at org.apache.openjpa.jdbc.sql.RowImpl.flush(RowImpl.java:850) > at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushSingleRow(BatchingPreparedStatementManagerImpl.java:249) > at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushBatch(BatchingPreparedStatementManagerImpl.java:157) > ... 138 more > This exception occurs because the particular JDBC driver checks the value of the 'length' variable passed to the 'PreparedStatement.setBinaryStream' method: > setBinaryStream(int parameterIndex, InputStream x, int length) > The 'length' parameter of method 'setBinaryStream' is supposed to be the length of the InputStream parameter. OpenJPA code is passing a value of '-1' for the length as the length is not known. Some JDBC drivers allow this value. Technically speaking the javadoc for 'PreparedStatement.setBinaryStream' doesn't state that a negative value is not acceptable or what should happen when a negative length is passed to 'setBinaryStream' (which is likely why some drivers allow a negative value and others do not). On the other hand, it doesn't make sense for a length of an InputStream to be negative. Given this, and the fact that OpenJPA is not aware of the length of the stream, I'll work on a solution which uses a JDBC 4.0 version of 'setBinaryStream' which doesn't take a length. The fix will of course require JDK 6 + JDBC 4.0 driver runtime. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira