首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring JPA保存实体。MySQLSyntaxErrorException错误

问Spring JPA保存实体。MySQLSyntaxErrorException错误
EN

Stack Overflow用户
提问于 2018-02-09 16:06:23
回答 1查看 348关注 0票数 0

我有一个会计实体类。我正在保存它,并得到错误below.Attached我的实体类,控制器,mysql表创建脚本。不确定错误是什么。非常感谢你的帮助!

代码语言:javascript
复制
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中创建的accountant表

代码语言:javascript
复制
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;

实体类为:

代码语言:javascript
复制
@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;
}

服务类别为:

代码语言:javascript
复制
@Service("accountantService")
public class AccountantServiceImpl implements AccountantService{

    @Autowired
    private AccountantRepository accountantRepository;

    @Override
    public Accountant saveAccountant(Accountant newAccountant, String role) {
        return accountantRepository.save(newAccountant);
    }
}

AccountantRepository类是:

代码语言:javascript
复制
@Repository("accountantRepository")
@Transactional
public interface AccountantRepository extends JpaRepository<Accountant, Long> {

    Accountant findByEmail(String email);
    Accountant findById(String id);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-09 16:19:07

将该列重命名为current_timestamp。因为current_timestamp是一个MySQL函数。

https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48701249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档