我有一个会计实体类。我保存它并得到下面的错误。附加我的实体类,控制器,mysql表创建脚本。不确定错误是什么。 非常感谢您的帮助!
2018-02-09 16:00:02.417 ERROR 11164 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'current_timestamp, email, email_verified, ic_number, name, password, phone_numbe' at line 1
在mysql中创建的会计表
CREATE TABLE IF NOT EXISTS accountant (
accountant_id varchar(255) NOT NULL,
email varchar(255) NOT NULL,
name varchar(255) NOT NULL,
password varchar(255) NOT NULL,
phone_number varchar(255) NOT NULL,
ic_number varchar(255) NOT NULL,
status int(11) NOT NULL,
verification_code VARCHAR(255),
email_verified varchar(1) NOT NULL DEFAULT 'N',
PRIMARY KEY (accountant_id)
);
ALTER TABLE ACCOUNTANT ADD COLUMN `current_timestamp` TIMESTAMP NULL DEFAULT current_timestamp;
实体类是:
@Entity
@Table(name = "accountant")
public class Accountant {
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name = "accountant_id", unique = true)
private String id;
@Column(name="email")
private String email;
@Column(name="name")
private String name;
@Column(name="password")
private String password;
@Column(name="phone_number")
private String phoneNumber;
@Column(name = "ic_number")
private String icNumber;
@Column(name = "status")
private int status;
@Column(name = "verification_code")
private String verificationCode;
@Column(name = "email_verified")
private String emailVerified;
@Column(name = "current_timestamp")
private Timestamp currentTimeStamp;
}
服务类是:
@Service("accountantService")
public class AccountantServiceImpl implements AccountantService{
@Autowired
private AccountantRepository accountantRepository;
@Override
public Accountant saveAccountant(Accountant newAccountant, String role) {
return accountantRepository.save(newAccountant);
}
}
AccountantRepository类是:
@Repository("accountantRepository")
@Transactional
public interface AccountantRepository extends JpaRepository<Accountant, Long> {
Accountant findByEmail(String email);
Accountant findById(String id);
}
答案 0 :(得分:0)
重命名列current_timestamp。因为current_timestamp是一个MySQL函数。
https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html