1

我将 eclipseLink 与 derby DB 一起使用,当我使用 commit( entityManager.getTransaction().commit();) 时遇到以下错误,该字段在日期为 java util 的实体中定义的。这里有什么问题?

输入数据的代码是:

Date date = new Date();
SimpleDateFormat parsedDate = new SimpleDateFormat("yyyy-mm-dd");
date = parsedDate.parse((String) memberValue);

成员值包含具有以下值的日期

"from": "2012-12-03"
"to": "2012-12-03"

实体如下

@Entity
@Table(name = "f1_LeaveRequest")
public class LeaveRequest {


    @Id
    @Column(name = "leaverequest_id")
    private String id;
    private String type;
    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date from;
    @Temporal(TemporalType.TIMESTAMP)

错误是:

Exception in thread "main" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "FROM" at line 1, column 47.
Error Code: 20000
Call: INSERT INTO f1_LeaveRequest (leaverequest_id, FROM, LENGTH, STATE, TO, TYPE) VALUES (?, ?, ?, ?, ?, ?)
    bind => [6 parameters bound]
4

3 回答 3

2

您可以使用注释标记字段@Column并为其提供不同的名称。

@Column(name ="from_timestamp")
@Temporal(TemporalType.TIMESTAMP)
private Date from;
于 2013-04-10T11:13:34.527 回答
1

我想那是因为FROM是 SQL 中的保留关键字。尝试将您的字段重命名为fromDateor fromTimestampor any,看看问题是否以这种方式解决。

于 2013-04-10T11:08:43.690 回答
1

FROM是保留关键字。使用有意义的东西,例如fromTime.

于 2013-04-10T11:18:26.077 回答