Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 72CF29FC129 for ; Thu, 18 Oct 2007 12:41:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 27546-04 for ; Thu, 18 Oct 2007 12:41:06 -0300 (ADT) X-Greylist: delayed 02:24:16.014157 by SQLgrey-1.7.5 Received: from agminet02.oracle.com (agminet02.oracle.com [141.146.126.229]) by postgresql.org (Postfix) with ESMTP id BBF099FC090 for ; Thu, 18 Oct 2007 12:41:04 -0300 (ADT) Received: from agminet01.oracle.com (agminet01.oracle.com [141.146.126.228]) by agminet02.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l9IDGrmS001245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 18 Oct 2007 08:16:53 -0500 Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l9IDGfhJ002670; Thu, 18 Oct 2007 08:16:41 -0500 Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id l9IDGedq007656; Thu, 18 Oct 2007 07:16:40 -0600 Received: from ailitche-pc.ca.oracle.com by acsmt350.oracle.com with ESMTP id 3302576311192713399; Thu, 18 Oct 2007 06:16:39 -0700 Message-ID: <001101c81189$2f3f52d0$4c349c0a@ca.oracle.com> From: "Andrei Ilitchev" To: Cc: "Marina Vatkina" Subject: Fw: postgresql experts please help Date: Thu, 18 Oct 2007 09:17:07 -0400 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-Mimeole: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-Whitelist: TRUE X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200710/95 X-Sequence-Number: 17667 Dear PostgreSQL jdbc experts, I created a table with identity: CREATE TABLE MAN (ID SERIAL, NAME VARCHAR(40), PRIMARY KEY (ID)) then through jdbc connection inserted a row into the table, then attempted to select pk value back through the same jdbc connection using currval - that failed with "not yet defined in this session" exception. What's wrong here? Please take a look at the test case and results below. Thanks a lot, Andrei ----- Original Message ----- From: "Marina Vatkina" To: Sent: Wednesday, October 17, 2007 6:57 PM Subject: Re: postgresql experts please help > Andrei, > > This is what I got so far: >> I actually don't see the problem here. All of what they're getting is >> the behavior I would expect. > > They suggested to contact pgsql-jdbc@postgresql.org to get more people to > look at the problem. > > Regards, > -marina > > Andrei Ilitchev wrote: >> I am trying to implement support for both Identity and sequenceObjects on >> the same database platform. >> For some reason currval doesn't work for me: called right after insert it >> throws exception indicating that nextval hasn't yet been called in this >> session - >> and yet insert is successfull: the pk value has been inserted. >> I am using >> Database: PostgreSQL Version: 8.2.5 >> Driver: PostgreSQL Native Driver Version: PostgreSQL 8.2 JDBC3 with SSL >> (build 505) >> Here's the JDBC test: >> public void testJdbcSequencing() throws java.sql.SQLException { >> Accessor accessor = >> this.getServerSession().getConnectionPool("default").acquireConnection(); >> java.sql.Connection conn = accessor.getConnection(); >> try { >> java.sql.PreparedStatement pstmt0 = >> conn.prepareStatement("select ID FROM MAN"); >> java.sql.ResultSet resultSet = pstmt0.executeQuery(); >> System.out.println("MAN before insert: "); >> while(resultSet.next()) { >> System.out.print(resultSet.getInt(1) + "; "); >> } >> resultSet.close(); >> System.out.println(); >> java.sql.PreparedStatement pstmt1 = conn.prepareStatement("INSERT INTO >> MAN (NAME) VALUES (null)"); >> int nInserted = pstmt1.executeUpdate(); >> pstmt1.close(); >> System.out.println("Inserted rows: " + nInserted); >> resultSet = pstmt0.executeQuery(); >> System.out.println("MAN after insert: "); >> while(resultSet.next()) { >> System.out.print(resultSet.getInt(1) + "; "); >> } >> resultSet.close(); >> pstmt0.close(); >> System.out.println(); >> System.out.println("Attempt: select currval(\'MAN_ID_seq\')"); >> resultSet = null; >> java.sql.PreparedStatement pstmt2 = >> conn.prepareStatement("select currval(\'MAN_ID_seq\')"); >> try { >> resultSet = pstmt2.executeQuery(); >> } catch (java.sql.SQLException ex) { >> ex.printStackTrace(); >> pstmt2.close(); >> // throw ex; >> } >> if(resultSet != null) { >> System.out.print("select currval: "); >> while(resultSet.next()) { >> System.out.println(resultSet.getString(1)); >> } >> resultSet.close(); >> pstmt2.close(); >> } >> System.out.println("Now attempt: select >> nextval(\'MAN_ID_seq\')"); >> resultSet = null; >> java.sql.PreparedStatement pstmt3 = >> conn.prepareStatement("select nextval(\'MAN_ID_seq\')"); >> try { >> resultSet = pstmt3.executeQuery(); >> } catch (java.sql.SQLException ex3) { >> ex3.printStackTrace(); >> pstmt3.close(); >> // throw ex; >> } >> if(resultSet != null) { >> System.out.print("select nextval: "); >> while(resultSet.next()) { >> System.out.println(resultSet.getString(1)); >> } >> resultSet.close(); >> pstmt3.close(); >> } System.out.println("Now again attempt: select >> currval(\'MAN_ID_seq\')"); >> resultSet = null; >> java.sql.PreparedStatement pstmt4 = >> conn.prepareStatement("select currval(\'MAN_ID_seq\')"); >> try { >> resultSet = pstmt4.executeQuery(); >> } catch (java.sql.SQLException ex4) { >> ex4.printStackTrace(); >> pstmt4.close(); >> // throw ex; >> } >> if(resultSet != null) { >> System.out.print("select currval: "); >> while(resultSet.next()) { >> System.out.println(resultSet.getString(1)); >> } >> resultSet.close(); >> pstmt4.close(); >> } } finally { >> >> this.getServerSession().getConnectionPool("default").releaseConnection(accessor); >> } >> } >> And here's result: >> MAN before insert: >> Inserted rows: 1 >> MAN after insert: >> 2; >> Attempt: select currval('MAN_ID_seq') >> org.postgresql.util.PSQLException: ERROR: currval of sequence >> "man_id_seq" is not yet defined in this session >> at >> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548) >> at >> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316) >> at >> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191) >> at >> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452) >> at >> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351) >> at >> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:255) >> at >> oracle.toplink.testing.tests.cmp3.advanced.AdvancedJunitTest.testJdbcSequencing(AdvancedJunitTest.java:246) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:585) >> at junit.framework.TestCase.runTest(TestCase.java:154) >> at junit.framework.TestCase.runBare(TestCase.java:127) >> at junit.framework.TestResult$1.protect(TestResult.java:106) >> at junit.framework.TestResult.runProtected(TestResult.java:124) >> at junit.framework.TestResult.run(TestResult.java:109) >> at junit.framework.TestCase.run(TestCase.java:118) >> at junit.framework.TestSuite.runTest(TestSuite.java:208) >> at junit.framework.TestSuite.run(TestSuite.java:203) >> at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22) >> at junit.extensions.TestSetup$1.protect(TestSetup.java:19) >> at junit.framework.TestResult.runProtected(TestResult.java:124) >> at junit.extensions.TestSetup.run(TestSetup.java:23) >> at junit.swingui.TestRunner$16.run(TestRunner.java:623) >> Now attempt: select nextval('MAN_ID_seq') >> select nextval: 216 >> Now again attempt: select currval('MAN_ID_seq') >> select currval: 216 >> Thanks a lot! >> Andrei >