Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B419E9FB91E for ; Thu, 1 Mar 2007 10:05:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 20089-01 for ; Thu, 1 Mar 2007 10:04:53 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.232]) by postgresql.org (Postfix) with ESMTP id 0C54C9FB909 for ; Thu, 1 Mar 2007 10:04:52 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id i31so31341wra for ; Thu, 01 Mar 2007 06:04:51 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=dzEFr3gwOufYxJ+oPa4OSBoLkq1uQbYZMor1ey2GRD9H5X0UBOWoRsWBK3aQ1v56J1QTQZrSRt+ZCX0fWKZy15+MXaQcy7JWpMHON0b3FZ8t/a1zz9lj/IZD2mD5vLzhjOPAbiP85rp4tY0JV3SY6k71ZCV3fx8aqxIYjhgFziY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=j9zO/fKMPwOsOcwaVBkkZrqt/LEt4eYDfKoMtQf8mNGRoNS6EQkEMRoSy9zvTgw/plRocytV5JML7ZvG4VpzikSSKFVVW6z3/2GBE2XNdlZWnyfxb14lFW59/s5aYV3dAdck46FRrMowRxld352NqfB1yz5JKhwxDB7cWkDQ4AM= Received: by 10.114.56.1 with SMTP id e1mr202984waa.1172757883803; Thu, 01 Mar 2007 06:04:43 -0800 (PST) Received: by 10.114.210.10 with HTTP; Thu, 1 Mar 2007 06:04:43 -0800 (PST) Message-ID: <40939ed60703010604j149caad2n92dccac2ae6f6824@mail.gmail.com> Date: Thu, 1 Mar 2007 17:04:43 +0300 From: "Ahmed Abd-el-Shafy Abd-Allah" To: pgsql-jdbc@postgresql.org Subject: Inserting "null" not working (Sun App Server, Postgres, EJB3)? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_65150_25088160.1172757883766" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.055 tagged_above=0 required=5 tests=BAYES_20, HTML_00_10, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200703/1 X-Sequence-Number: 16715 ------=_Part_65150_25088160.1172757883766 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, I posted this question to the Java forums at Sun, but I think the problem is attributable to something in PostgreSQL. I have a table with some columns that allow null values. From within my Java code, I have an EJB3 entity which models that table. I know that the overall code works because in the beginning I did not allow null values at the database level (using NOT NULL), and everything worked fine. But after changing the database to allow null values, I ran into the following problem. If the entity has null values for some of its fields, when I call persist() on the entity manager, I get the following exception (which I have edited to only show one of the fields for brevity): Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: ERROR: column "pools" is of type smallint but expression is of type character varyingError Code: 0 Call:INSERT INTO MYTABLE (POOLS) VALUES (?) bind => [*null*] Query:InsertObjectQuery(aaacs.rex.ejb.entities.MyTable@10b287f) The underlying database is PostgreSQL 8.1.4 (and the jdbc driver is 8.1.407, JDBC3), and I am using the Sun 9.0 application server. I searched on the internet for clues to this problem, and found more than one post that indicate that the PostgreSQL JDBC driver - and in fact other JDBC drivers - may be trying to interpret "null" as a number (that is the type of the column "pools" by the way). Therefore it fails. If I were using plain JDBC it would be easy to solve this problem because I would use "setNull()" explicitly. The problem is that I am using EJB3, which means all I can do is call persist on the manager - I do not have finegrained control over what the container is doing actually. Can anyone help here? I am really stuck. I know that another solution would be to explicitly cast the value inside the SQL insert, but again, I have no access to the query because it is being constructed by the container... Many thanks in advance for any and all advice. One more thing: is the only solution using "protocolVersion=2"? I have looked at the FAQ at the JDBC PostgreSQL web site, and that seems to be the advice right now. Since the code that needs to be modified is within Toplinnk, or within Sun's server, I can't really change it... so falling back to protocolVersion 2 might be my only choice. Any thoughts? -A ------=_Part_65150_25088160.1172757883766 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello,

I posted this question to the Java forums at Sun, but I think the problem is attributable to something in PostgreSQL.

I have a table with some columns that allow null values. From within my Java code, I have an EJB3 entity which models that table. I know that the overall code works because in the beginning I did not allow null values at the database level (using NOT NULL), and everything worked fine. But after changing the database to allow null values, I ran into the following problem.

If the entity has null values for some of its fields, when I call persist() on the entity manager, I get the following exception (which I have edited to only show one of the fields for brevity):

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 
060412)): oracle.toplink.essentials.exceptions.DatabaseException
 
Internal Exception: org.postgresql.util.PSQLException : ERROR: column
"pools" is of type smallint but expression is of type character varyingError Code: 0
 
Call:INSERT INTO MYTABLE (POOLS) VALUES (?)
bind => [ null]
Query:InsertObjectQuery(aaacs.rex.ejb.entities.MyTable@10b287f)


The underlying database is PostgreSQL 8.1.4 (and the jdbc driver is 8.1.407, JDBC3), and I am using the Sun 9.0 application server.

I searched on the internet for clues to this problem, and found more than one post that indicate that the PostgreSQL JDBC driver - and in fact other JDBC drivers - may be trying to interpret "null" as a number (that is the type of the column "pools" by the way). Therefore it fails. If I were using plain JDBC it would be easy to solve this problem because I would use "setNull()" explicitly.

The problem is that I am using EJB3, which means all I can do is call persist on the manager - I do not have finegrained control over what the container is doing actually.

Can anyone help here? I am really stuck. I know that another solution would be to explicitly cast the value inside the SQL insert, but again, I have no access to the query because it is being constructed by the container...

Many thanks in advance for any and all advice.

One more thing: is the only solution using "protocolVersion=2"? I have looked at the FAQ at the JDBC PostgreSQL web site, and that seems to be the advice right now. Since the code that needs to be modified is within Toplinnk, or within Sun's server, I can't really change it... so falling back to protocolVersion 2 might be my only choice. Any thoughts?

-A ------=_Part_65150_25088160.1172757883766--