Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-dev] Case Sensitivity in JPA/EclipseLink

Hello!
I am having a bit of trouble deciphering the JPA spec's stance on case sensitivity, specifically with regards to database Table/Column names. I cannot find anything in the JPA specification that dictates if Table/Column names should/shouldn't default to UPPERCASE or lowercase. It appears to me that this may be provider (and more specifically database) specific. Is this a correct assumption?

The reason I ask is because I have been investigating EclipseLink's handling of DatabaseField and the case sensitivity built into that implementation (specifically equals() and hashcode()). In my investigation, I found that EclipseLink makes many assumptions about the case sensitivity of database field names. In many situations, EclipseLink basically equates the attribute value <--> database name! As a part of my fix, unfortunately, I started breaking these usecases and I am now hitting a wall because the specification is oddly silent.

For instance, assume these mappings:
-------------------------
@Entity
public class Employee {
    @EmbeddedId EmployeeId empId;
}

@Embeddable
public class EmployeeId {
    String firstName;
    String lastName;
}

@Entity
@IdClass(DependentId.class)
public class Dependent {
    @Id
    @Column(name="dep_name") // default column name is overridden
    String name;

    @MapsId("empPK")
    @JoinColumns({
        @JoinColumn(name="FK1", referencedColumnName="firstName"),
        @JoinColumn(name="FK2", referencedColumnName="lastName")
    })
    @ManyToOne Employee emp;
}

@Embeddable
public class DependentId {
    String name;
    EmployeeId empPK; // corresponds to PK type of Employee
}
--------------------------------
This mapping example is taken right out of the JPA spec. The portion I am questioning is the `referencedColumnName`. Notice that in this example, the mapping uses the lowercase, attribute names. There are other examples of `referencedColumnName` in the specification that use UPPERCASE (but the specification fails to show the mappings that the UPPERCASE are referencing).

Consider in the above usecase if the `referencedColumnName`were given as UPPERCASE. Should we assume the reference ignores case and just figure it out? or should we fail with an error like:
```
missing FK reference column "FIRSTNAME" in table "Employee"
```

Should our implementation ignore case by default? There currently exists a Platforms to change that default (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.shouldIgnoreCaseOnFieldComparisons) and that default is false. I think that default may be fine, but it depends on how we want to handle when users pass in specific cased strings and how we handle them.

Thanks,
Will Dazey

Back to the top