列出数据库内容时发生休眠错误

v1l68za4  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(298)

我正在尝试访问一个本地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;
}
bvk5enib

bvk5enib1#

您可以删除@table和@column注解中的所有名称值。
无论如何,hibernate都会选择默认值。
例如,表名肯定不是“default”

相关问题