Reputation: 253
Im using the following code the insert data to JPA and Im getting error when im trying to do the commit ,the object is with the full data so i dont understand what am I missing here,any idea?
entityManager.getTransaction().begin();
entityManager.persist(object);
entityManager.getTransaction().commit();
the entity look like this with all the getters and setters
@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;
}
the error is:
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])
Upvotes: 0
Views: 973
Reputation: 12505
wow, cool. you have an attribute called "from" and it clashes with SQL reserved word. I would say it's a bug in your jpa provider, but who knows, maybe such behaviour is jpa compliant. as a workaround you can rename the column in the database and add a @column annotation to from attribute, with name="newcolumnname"
Upvotes: 0
Reputation: 6969
FROM
is a sql reserved keyword.
Just change the variable name or use the @Column annotation to change the column name of the table column.
Upvotes: 4