在MySQL中我有创建表的脚本
create table account (
AccountId int not null auto_increment,
Login varchar(31),
Password varchar(31),
primary key (AccountId)
);
在java类中我有这个表的模型
@Entity
@Table(name = "account")
public class Account {
@Column(name = "AccountId", nullable = false, unique = true)
private Integer AccountId;
private String Login;
private String Password;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getAccountId() {
return AccountId;
}
在存储库包中
public interface AccountRepository extends JpaRepository<Account, Integer> {
Account findAccountByLoginAndPassword(String login, String password);
}
在客户端站点我尝试发送请求登录名和密码但是我在服务器站点有错误
2018-05-28 14:46:15.464 INFO 20300 --- [nio-8080-exec-2] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select account0_.account_id as account_1_0_, account0_.login as login2_0_, account0_.password as password3_0_ from account account0_ where account0_.login=? and account0_.password=?
`ERROR 20300 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'account0_.account_id' in 'field list`
' 这意味着我应该将 MySQL 表中的列名称更改为 account_id?
最佳答案
“这意味着我应该将 MySQL 表中的列名更改为 account_id”
是的,这是一个好主意,因为命名约定,但您也可以配置适当的命名策略:
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
或者您可以尝试以小写形式打印您的列名。 (如果你的 MySQL 是基于 Windows 的)
@Column(name="accountid", nullable = false, unique = true)
关于java - 字段列表中的 Spring Boot JPA 未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50567041/