即時通訊使用以下代碼插入數據到JPA和我得到錯誤,當我試圖做提交時,對象是與完整的數據,所以我不明白我失去了什麼這裏有什麼想法?錯誤,同時創建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])
許多數據庫將允許您使用保留字作爲標識符(如' 「FROM」')。您可以通過'@ Column'註釋('@Column(name =「\」FROM \「」)'')來做到這一點。 – 2013-03-17 17:24:22
@BrianVosburgh我不知道,但是這又值得嗎?就我個人而言,我覺得這種方法會混淆查詢可讀性.... – Thihara 2013-03-18 04:19:45