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?
Use @Column(name="accountid", nullable = false, unique = true)
Columns in Mysql are case insensitive. If you use case sensitive column name in @Column
then it will convert camel case to snake case.
"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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With