Skip to content
Advertisement

Spring Boot JPA unknown column in field list

In MySQL I have script that create table

create table account (
AccountId int not null auto_increment,
Login varchar(31),
Password varchar(31),
primary key (AccountId)
);

In java class i have model to this table

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

In Repository package

public interface AccountRepository extends JpaRepository<Account, Integer> {
    Account findAccountByLoginAndPassword(String login, String password);
}

In client site i try send in request login and password but i have error in server site

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`

‘ That mean I should change my column name in MySQL table to account_id?

Advertisement

Answer

“That means I should change my column name in MySQL table to account_id”

Yep, this is a good idea because of naming convention, but also you can configure proper naming strategy:

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy

Or you can try to print your column name in lower case. (If your MySQL is Windows based)

@Column(name="accountid", nullable = false, unique = true)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement