Java 运行时休眠“找不到表”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20152311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate "Table not found" error on runtime
提问by Günay Gültekin
I have created database successfully with no error and also I added dummy data after creation. Next, I try to get data from database however I have seen an error on console. It tries to create table which was created before.No need to recreate :/ I have searched internet and couldnt find anything related this.
我已经成功创建了数据库,没有错误,并且在创建后添加了虚拟数据。接下来,我尝试从数据库中获取数据,但是我在控制台上看到了一个错误。它尝试创建之前创建的表。无需重新创建:/ 我在互联网上搜索过,但找不到任何与此相关的内容。
I use MYSQL db, hibernate 4. These 3 classes (Material,MaterialProjectBrief,MaterialProjectImage) dont have any onetomany,manytoone annotations. I have other tables the same structure, they are working well (doing CRUD). I use annotations only I added mapping classed to hibernate.cfg.xml.
我使用 MYSQL db,hibernate 4。这 3 个类(Material、MaterialProjectBrief、MaterialProjectImage)没有任何 onetomany、manytoone 注释。我有其他具有相同结构的表,它们运行良好(执行 CRUD)。我只使用注释,我添加了分类到 hibernate.cfg.xml 的映射。
(Sorry for writing quickly because I have to leave the office now.
(抱歉写得太快了,因为我现在必须离开办公室。
Here is the MaterialProjectImage class.
这是 MaterialProjectImage 类。
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class MaterialProjectImage implements Serializable {
private static final long serialVersionUID = 3886003470849765887L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name="LINK")
private String link;
@Column(name="TITLE")
private String title;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Here is the log.
这是日志。
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.material
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, aboutus, about, s?temap, v?s?on, worklocat?on, m?ss?on, customers, rad, goal]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.materialprojectbrief
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, t?tle, shortbr?ef, ?conl?nk]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: MaterialProjectImage
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.person
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, username, ?nfo, ?mgpath, name, role, password]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.project
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, faq, t?tle, url, ?nstallat?on]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.projectwebview
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, ?ntro, ?mgl?nk, project_id, type]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: [fk_9qlhqdt00j5a5hknep10wu44c]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [fk_9qlhqdt00j5a5hknep10wu44c, pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: PORTAL.project_document
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [document_id, project_id]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: [fk_6gwm4ft0jihnaprel3uem1or6, fk_ctnt2crdturw4k3xc5w4r5571]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [fk_6gwm4ft0jihnaprel3uem1or6, uk_6gwm4ft0jihnaprel3uem1or6, fk_ctnt2crdturw4k3xc5w4r5571]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: MaterialProjectImage
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: create table MaterialProjectImage (id integer not null auto_increment, LINK varchar(255), TITLE varchar(255), primary key (id))
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: Table 'materialprojectimage' already exists
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.material
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[id、aboutus、about、s?temap、v?s?on、worklocat?on、m?ss?on、customers、rad、goal]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.materialprojectbrief
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[id、t?tle、shortbr?ef、?conl?nk]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
信息:HHH000262:找不到表:MaterialProjectImage
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.person
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[id、用户名、?nfo、?mgpath、名称、角色、密码]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.project
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[id、faq、t?tle、url、?nstallat?on]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.projectwebview
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[id、?ntro、?mgl?nk、project_id、类型]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[fk_9qlhqdt00j5a5hknep10wu44c]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[fk_9qlhqdt00j5a5hknep10wu44c,pr?mary]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000261:找到的表:PORTAL.project_document
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000037:列:[document_id,project_id]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000108:外键:[fk_6gwm4ft0jihnaprel3uem1or6, fk_ctnt2crdturw4k3xc5w4r5571]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.TableMetadata
信息:HHH000126:索引:[fk_6gwm4ft0jihnaprel3uem1or6、uk_6gwm4ft0jihnaprel3uem1or6、fk_ctnt2crdturw4k3xc5w4r5571]
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
信息:HHH000262:找不到表:MaterialProjectImage
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
错误:HHH000388:不成功:创建表 MaterialProjectImage(id 整数不为 null auto_increment,LINK varchar(255),TITLE varchar(255),主键 (id))
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
错误:表“materialprojectimage”已经存在
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
信息:HHH000232:架构更新完成
采纳答案by mohr_michael_a
I suspect it is case sensitivity. As per the MySQL documentation:
我怀疑这是区分大小写的。根据 MySQL 文档:
How table and database names are stored on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can set when starting mysqld. lower_case_table_names can take the values shown in the following table. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.
表和数据库名称在磁盘上的存储方式和在 MySQL 中的使用方式受 lower_case_table_names 系统变量的影响,您可以在启动 mysqld 时设置该变量。lower_case_table_names 可以采用下表中显示的值。在 Unix 上,lower_case_table_names 的默认值为 0。在 Windows 上,默认值为 1。在 Mac OS X 上,默认值为 2。
Value Meaning 0 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result. 1 Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases. 2 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.
值 含义 0 表和数据库名称使用 CREATE TABLE 或 CREATE DATABASE 语句中指定的字母大小写存储在磁盘上。名称比较区分大小写。如果您在具有不区分大小写的文件名的系统(例如 Windows 或 Mac OS X)上运行 MySQL,则不应将此变量设置为 0。如果在不区分大小写的文件系统上使用 --lower-case-table-names=0 将此变量强制为 0 并使用不同的字母访问 MyISAM 表名,则可能会导致索引损坏。1 表名以小写形式存储在磁盘上,名称比较不区分大小写。MySQL 在存储和查找时将所有表名转换为小写。此行为也适用于数据库名称和表别名。2 表和数据库名称使用 CREATE TABLE 或 CREATE DATABASE 语句中指定的字母存储在磁盘上,但 MySQL 在查找时将它们转换为小写。名称比较不区分大小写。这仅适用于不区分大小写的文件系统!InnoDB 表名以小写形式存储,例如lower_case_table_names=1。
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitive.html
Looking at your error logs it seems highly likely:
查看您的错误日志似乎很有可能:
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: MaterialProjectImage
信息:HHH000262:找不到表:MaterialProjectImage
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
ERROR: HHH000388: Unsuccessful: create table MaterialProjectImage (id integer not null auto_increment, LINK varchar(255), TITLE varchar(255), primary key (id))
错误:HHH000388:不成功:创建表 MaterialProjectImage(id 整数不为 null auto_increment,LINK varchar(255),TITLE varchar(255),主键 (id))
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
ERROR: Table 'materialprojectimage' already exists
错误:表“materialprojectimage”已经存在
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
22.Kas.2013 20:17:05 org.hibernate.tool.hbm2ddl.SchemaUpdate 执行
INFO: HHH000232: Schema update complete
信息:HHH000232:架构更新完成
回答by Günay Gültekin
I have fixed the problem by adding @Table(name="material")annotation under the @Entityannotation according to here. Before doing this, I changed the lower_case_table_names however the problem still continued. Then I have realized to add tab annotation. Thanks.
我已根据此处通过在@Entity注释下添加@Table(name="material")注释来解决此问题。在这样做之前,我更改了lower_case_table_names,但问题仍然存在。然后我意识到添加标签注释。谢谢。