persistence@glassfish.java.net

Code change for Issue 805 : Postgresql and non-default schema

From: Pramod Gopinath <Pramod.Gopinath_at_Sun.COM>
Date: Fri, 25 Aug 2006 16:05:16 -0700

Hi Tom
  The code change attached to this email deals with resolving issue: 805
https://glassfish.dev.java.net/issues/show_bug.cgi?id=805

This issue is relevant only to Postgresql database.

Currently if the user has a table defined in a schema other than the
default schema (public), then the following error is thrown :
============================================
Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.6 (Build
060630)):
oracle.toplink.essentials.exceptions.DatabaseException

Internal Exception: org.postgresql.util.PSQLException: ERROR: relation
"public.address_id_seq" does not
existError Code: 0
Call:select currval(current_schema()|| '.address_id_seq')
============================================

When I defined the PostgreSQLPlatform, I had defined the method
buildSelectQueryForNativeSequence(String seqName, Integer size)
which would try to get the last value from the sequence using the call :
select currval(current_schema()" + "|| \'." + seqName + "\')");

This is incorrect. There could be cases where the user might create
entities in other schema's. So logically the user might have a
connection to schema "public" and try to lookup entities that are in
some other schema. But the call for current_schema() would incorrectly
look for the sequence in the "public" schema. Hence I am removing the
call to "current_schema()" and the user would have to ensure that they
have correctly provided the fully qualified sequence name.

Thanks
Pramod




Index: src/java/oracle/toplink/essentials/platform/database/PostgreSQLPlatform.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/platform/database/PostgreSQLPlatform.java,v
retrieving revision 1.7
diff -r1.7 PostgreSQLPlatform.java
161c161
< selectQuery.setSQLString("select currval(current_schema()" + "|| \'." + seqName + "\')");
---
>         selectQuery.setSQLString("select currval(\'"  + seqName + "\')");