我一直在尝试在Ubuntu 14.04上使用MySQL和Toplink设置Glassfish,所以我用JSF 2.2创建了一个简单的WebApp来测试一切是否正常运行。但是,我遇到了一些我不太了解的事情。我指定了@Entity(name =“substances”),如你所见,我的表的小写名称(已存在于数据库中)。但是,在我看来,Toplink将其名称翻译成大写,显然未能找到它:
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)
这是Substance类:
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; }
}
此外,我确实使用mysqlcheck工具检查表'decalin.substances'是否存在。但为什么一直在寻找'decalin.SUBSTANCES'?
当我在Windows 8.1上运行相同的代码时,没有报告任何问题......
所以,我最终将@Table(name =“substances”)注释添加到Substance类中,一切都很顺利。
我的问题是,为什么Toplink在Ubuntu上使用大写,尽管在@Entity中将'name'属性设置为“items”?为什么它在Windows上运行?也许我错过了Toplink设置中的内容(persistence.xml在两种情况下都是相同的)。
答案 0 :(得分:1)
Windows没有区分大小写的文件系统。正如您在/ var / lib / mysql中看到的那样(或者您的mysql存储数据),每个数据库表都有自己的文件(扩展名为.frm和.ibd)。因此,在不区分大小写的文件系统表名称不区分大小写的情况下,区分大小写(如Linux上的ext4)。有关详细信息,请参阅MySQL documentation。