gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 17:31:06 25 4
gpt4 key购买 nike

我正在尝试访问本地 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com