Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quoting problem with JPA2 (EclipseLink) and PostgreSQL

With PostgreSQL, I have to double-quote all identifiers or they'll be implicitly lower-cased. I'd prefer to preserve case since "lastLoginAttemptIpAddress" is so much more readable than "lastloginattemptipaddress".

I have created an orm.xml file with (full contents below). That caused EclipseLink to quote most of the identifiers, but it specifically did not quote the column name when defining a foreign key constraint. How can I tell EL to quote all identifiers?

I have also tried using quotes in the explicitly specified table / column names to cause EL to quote identifiers. First and foremost, that doesn't work either -- same behavior. In addition to that, (1) that forces me to specify names twice (I already did so in the property accessor names) and in a manner that is invisible to refactoring tools, (2) it is wrong -- the quotes aren't part of the name, (3) it forces me to fix quoting at POJO level when it is actually a specific trait of the database system I am using.

orm.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd">

    <description>description here</description>
    <persistence-unit-metadata>
        <persistence-unit-defaults>
            <delimited-identifiers />
        </persistence-unit-defaults>
    </persistence-unit-metadata>

</entity-mappings>

entity class:

@Entity
public class UserX {

    ...

    @Id
    @GeneratedValue(generator = "UserX_id_seq")
    @SequenceGenerator(name = "UserX_id_seq", allocationSize = 1)
    public int getId() { ... }

    ...

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    public UserX getModificationUser() { ... }

}

the generated query (note the missing quotes around the column name):

ALTER TABLE "UserX" ADD CONSTRAINT "FK_UserX_modificationUser_id" FOREIGN KEY (modificationUser_id) REFERENCES "UserX" (id)
like image 653
Martin Geisse Avatar asked Dec 17 '25 04:12

Martin Geisse


1 Answers

Seems to be a bug that the foreign key column are not quoted. Please log the bug in EclipseLink and vote for it.

Does the DDL fail? A work around would be to define the DDL in a script, or switch just that column to be all lower case.

like image 196
James Avatar answered Dec 19 '25 23:12

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!