Bug 374156 - Observed 'org.postgresql.util.PSQLException: ERROR: syntax error at or near "."' when specifying the schema in persistence-unit-defaults and creating indexes
Summary: Observed 'org.postgresql.util.PSQLException: ERROR: syntax error at or near "...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: postgresql
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-13 19:36 EDT by Aaron Dockter CLA
Modified: 2022-06-09 10:19 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Dockter CLA 2012-03-13 19:36:06 EDT
Build Identifier: 2.3.2.v20111125-r10461

In our ORM.xml file we have specified a global schema name as follows:

    <persistence-unit-metadata>
        <persistence-unit-defaults>
        	<schema>MYSCHEMA</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>

We have an Entity class that we are adding and index to, also in the ORM.xml:

    <entity class="com.cm.persistence.MyTable">
	<index name="IDX_GUIDCOLUMN" unique="true">
	    <column-name>GUIDCOLUMN</column-name>
	</index>
    </entity>

The class looks like:

@Entity
@Table(name = "MyTable")
public class MyTable implements Serializable, Cloneable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "GUIDCOLUMN", nullable = false)
    private String myGUID;

    public void setMyGUID(String myGUID) {
        this.myGUID = myGUID;
    }

    public String getMyGUID() {
        return myGUID;
    }
}


Upon creating the index for this table, I get the following error:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
  Position: 26
Error Code: 0
Call: CREATE UNIQUE INDEX MYSCHEMA.IDX_GUIDCOLUMN ON MYSCHEMA.MyTable (GUIDCOLUMN)


In the DatabasePlatform.java (3109) class file I found that it is currently appending the qualifier to both the name of the table as well as the name of the index.  The qualifier should not be included in the name of the index as that is a Syntax exception in POSTGRES.


public String buildCreateIndex(String fullTableName, String indexName, String qualifier, boolean isUnique, String... columnNames) {
        StringBuilder queryString = new StringBuilder();
        if (isUnique) {
            queryString.append("CREATE UNIQUE INDEX ");
        } else {
            queryString.append("CREATE INDEX ");
        }
-       if (!qualifier.equals("")) {
-            queryString.append(qualifier).append(".");
-       }
        queryString.append(indexName).append(" ON ").append(fullTableName).append(" (");
        queryString.append(columnNames[0]);
        for (int i = 1; i < columnNames.length; i++) {
            queryString.append(", ").append(columnNames[i]);
        }
        queryString.append(")");
        return queryString.toString();
    }


Reproducible: Always

Steps to Reproduce:
1. Create an orm.xml file that specifies a global schema using persistence-unit-defaults
2. Create an index for a specific entity on a table in that global schema either using the orm <index> notation, or by using the JPA annotations.
3. Run persistence for the first time so that it will create tables and indexes

See Details for a potential fix.
Comment 1 Tom Ware CLA 2012-03-15 13:47:55 EDT
You should be able to workaround this by creating a subclass of PostgreSQLPlatform and overriding the offending method and then enabling it using the eclipselink.target-database persistence unit property.
Comment 2 Aaron Dockter CLA 2012-03-29 13:24:53 EDT
Thanks, that worked for me.
Comment 3 Tom Ware CLA 2012-04-05 08:30:47 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 Samba Kolusu CLA 2015-12-08 15:28:17 EST
i remember i did not have this problem earlier with eclipse bundled with glassfish 4.1, but after upgrading to glassfish 4.1.1 i am getting this issue. is it, by chance, any regression?
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:19:05 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink