我使用以下代码将数据插入JPA并且我在尝试提交时遇到错误,对象是完整数据所以我不明白我在这里缺少什么,任何想法?
entityManager.getTransaction().begin();
entityManager.persist(object);
entityManager.getTransaction().commit();
实体看起来像所有的getter和setter
@Entity
public class LeaveRequest {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String type;
private String from;
private String to;
private String length;
private String state;
public int getId() {
return id;
}
错误是:
Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "FROM" at line 1, column 31.
Error Code: 20000
Call: INSERT INTO LEAVEREQUEST (ID, FROM, LENGTH, STATE, TO, TYPE) VALUES (?, ?, ?, ?, ?, ?)
bind => [6 parameters bound]
Query: InsertObjectQuery(LeaveRequest [id=1, type=VACATION, from=2012-12-27, to=2012-12-27, length=1 day, state=Rejected])
答案 0 :(得分:4)
FROM
是一个sql reserved关键字。
只需更改变量名称或使用@Column注释更改表格列的列名称。
答案 1 :(得分:0)