java - 列出数据库内容时出现 hibernate 错误

标签 java mysql hibernate playframework ebean

我正在尝试访问本地 MYSQL 数据库,该数据库有一个名为 default 的表,其中包含列 name 、 id 和 help 。我正在使用带有 JPA、Ebean 的 Play 框架。

这是我收到的错误消息。

[warn] o.h.e.j.s.SqlExceptionHelper - SQL Error: 1064, SQLState: 42000 
[error] o.h.e.j.s.SqlExceptionHelper - You have an error in your 
SQL syntax; check the manual that corresponds to your MySQL 
server version for the right syntax to use near 'default language0_' at line 1
....
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2167)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1930)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892)
at org.hibernate.loader.Loader.doQuery(Loader.java:937)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default language0_' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:960)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1019)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2167)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1930)

这是列出所有条目的调用:

private Stream<Language> list(EntityManager em) {
    List<Language> persons = em.createQuery("select p from Language p").getResultList();
    return persons.stream();
}

这是我正在使用的模型: 封装模型;

import javax.persistence.*;

@Entity
@Table(name="default")
public class Language {

@Id
@Column(name="`id`")
@GeneratedValue(strategy=GenerationType.AUTO)
public Long id;

@Column(name="`text`")
public String text;

@Column(name="`help`")
public String help;
}

最佳答案

您可以删除@Table和@Column注释中的所有名称值。

Hibernate 无论如何都会选择默认值。

例如表名称肯定不是“默认”

关于java - 列出数据库内容时出现 hibernate 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50649285/

相关文章:

mysql - 使用 Hibernate 查询缓存时的缓存更新

java - 从 Play Framework 2.3.x 中的绝对路径提供静态资源

java - 即使 containsKey() 返回 true,从 HashMap 检索时也会出现空指针异常

php - 将 PHP 日期时间转换为 MySQL RFC-822 RSS Feed 的有效日期时间

python - 在sqlalchemy中,什么对应于mysql函数 'load_file'?

java - 为什么当父级更新时,Hibernate 会执行多个更新子级的查询?

java - 我们可以使用带有破折号 `-` 或下划线 `_` 的 spring-boot 外部配置文件名吗?

java - (android studio)无法更改webview中的 "Webpage not available"页面

mysql - mysql SP 中的 IF/ELSE 结构不起作用

java - Hibernate Criteria API - 创建自动连接