Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325921 - DB column names in lowercase are capitalized in referencedColumnName attribute
Summary: DB column names in lowercase are capitalized in referencedColumnName attribute
Status: REOPENED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-21 23:03 EDT by welljim CLA
Modified: 2022-06-09 10:35 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description welljim CLA 2010-09-21 23:03:02 EDT
Build Identifier: 20100218-1602

If a column name in the DB contains lowercase characters, then it is not possible to correctly use that column in the referencedColumnName attribute. For instance, consider the following example:

@ManyToOne
@JoinColumns({
	@JoinColumn(name = "viewId", referencedColumnName = "id"),
	@JoinColumn(name = "customerId", referencedColumnName = "customerId")
})
private MyEntity myEntity;


Although the DB columns and corresponding entity fields are called "id" & "customerId", using those names in "referencedColumnName" results in errors during runtime:

org.eclipse.persistence.exceptions.QueryException
Exception Description: The parameter name [id] in the query's selection criteria does not match any parameter name defined in the query.


Changing the referenced column names to a capitalized equivalent as shown below, resolves the problem and the application runs as expected. However, now the Eclipse editor does not recognize the capitalized names and it underlines them in red with the following error:

Referenced column "ID" in join column "viewId" cannot be resolved.
&
Referenced column "CUSTOMERID" in join column "customerId" cannot be resolved.

The errors appear in the Eclipse editor after establishing a DB connection in the JPA plugin (Database Connections)

@ManyToOne
@JoinColumns({
	@JoinColumn(name = "viewId", referencedColumnName = "ID"),
	@JoinColumn(name = "customerId", referencedColumnName = "CUSTOMERID")
})
private MyEntity myEntity;

Reproducible: Always
Comment 1 Tom Ware CLA 2010-09-22 07:31:03 EDT
Use delimiters either by delimiting the individual columns in your annotations.

e.g. @JoinColumn(name = "\"viewId\"", referencedColumnName = "\"id\"")

Or by setting it to the default in your orm xml

i.e.

    <persistence-unit-metadata>
        <persistence-unit-defaults>
            <delimited-identifiers/>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
Comment 2 welljim CLA 2010-09-23 19:43:27 EDT
I tried delimiting the column names as suggested, the workaround produces the following results:
- Dali plugin (i.e., Eclipse Editor) no longer underlines the column names as incorrect (please note that this is also the case without the delimiters)
- However, the exact same errors that I described originally are still produced at runtime, despite the use of the delimiters.

In other words, enclosing mixed lowercase/uppercase column names inside escaped double quotes (\") cannot be used as a workaround, delimiting such column names does not seem to have any effect.

Perhaps for new projects the cost of changing all column names in a DB can be manageable (although I suspect many would criticize an ORM provider for imposing such restrictions). But for existing systems such a change on the DB level may be prohibitive.

I'm reopening the issue for your consideration, at the moment the only workaround seems to be the use of capitalized names in Eclipse, though that is making development really difficult (i.e., we have about 50 entities in the package explorer that are marked with the red "x" (i.e., to imply that they contain errors). We are no longer able to distinguish which classes do have real errors without inspecting them one by one, at every change we make in the code. This is a ton of work..
Comment 3 Tom Ware CLA 2010-09-30 15:16:14 EDT
My quick run our our delimited model shows me case being maintained property with delimited identifiers used.  Is it possible to post a recreation of the issue?

What DB are you using?
Comment 4 welljim CLA 2010-09-30 16:15:09 EDT
The DB is MySQL (5.1.41, community ver)

The problem appears only when entity keys are composite, where referencedColumnName needs to be explicitly defined in relationships. 

I'll try to simulate it outside our installation and post an example.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:35:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink