Search code examples
javamysqltoplink

Why does Toplink force uppercase in table names?


I have been trying to setup Glassfish with MySQL and Toplink on Ubuntu 14.04, so I created a simple WebApp with JSF 2.2 to test if everything is running fine. However, I ran into something I don't quite understand. I specified @Entity (name = "substances"), which is, as you see, lowercase name of my table (already existing in the database). But, it seems to me, that Toplink translated its name into uppercase and, obviously, failed to find it:

javax.persistence.RollbackException: Exception [EclipseLink-4002]
(Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.DatabaseException Internal Exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table
'decalin.SUBSTANCES' doesn't exist Error Code: 1146 Call: INSERT INTO
SUBSTANCES (substance_name) VALUES (?) bind => [1 parameter bound] Query:
InsertObjectQuery(org.malik.decalin.beans.Substance@58759bfa)

This is Substance class:

package org.malik.decalin.beans;

import org.malik.decalin.dao.DataAccess;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity (name = "substances")
@Named
@RequestScoped
public class Substance implements Serializable {

@Id
@Column (name = "substance_id")
@GeneratedValue (strategy = GenerationType.IDENTITY)
Long id;

@Column (name = "substance_name")
String substanceName;

public String create() {
    DataAccess da = new DataAccess();
    Substance substance = new Substance();
    substance.setId(id);
    substance.setSubstanceName(substanceName);
    da.createSubstance(substance);
    return "jest";
}

// getters and setters

public Long getId() { return id; }
public void setId(Long id) { this.id = id; }

public String getSubstanceName() { return substanceName; }
public void setSubstanceName(String substanceName) { this.substanceName = substanceName; }    
}

Moreover, I did check with mysqlcheck tool that table 'decalin.substances' exists. But why does it keep looking for 'decalin.SUBSTANCES'?

When I ran the same code on Windows 8.1, no problems were reported...

So, I finally added @Table (name = "substances") annotation to the Substance class and everything went fine.

My question is, why did Toplink use uppercase on Ubuntu despite setting 'name' attribute in @Entity to "substances"? Why did it work on Windows? Maybe I missed something in the Toplink settings (persistence.xml is the same in both cases).


Solution

  • Windows does not have case-sensitive filesystem. As you can see in /var/lib/mysql (or whereever your mysql stores data) each database table has it's own files (with .frm and .ibd extensions). So on case insensitive filesystem table names are not case sensitive, on case sensitive (like ext4 on Linux) they are. See MySQL documentation for more information.