列出DB的内容时出现休眠错误

时间:2018-06-01 18:36:17

标签: java mysql hibernate playframework ebean

我正在尝试访问一个本地MYSQL数据库,该数据库有一个名为default的表,包含列名称和id以及帮助。我正在使用Play框架和JPA,Ebean。

这是我收到的错误消息。

[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;
}

1 个答案:

答案 0 :(得分:0)

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

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

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