<AST>:1:33:HQL 插入的意外 AST 节点错误
<AST>:1:33: unexpected AST node error for a HQL insert
这是我的实体 class :
@Entity
@Table(name = "courier_upload_queue")
public class CourierUploadQueue {
private int id;
private String crp_code;
private Status status;
private Date time_created;
private Date last_update;
private String courier_name;
private Integer retry_count;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@Enumerated(EnumType.STRING)
@Column(name= "status", nullable= false)
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
@Column(name= "crp_code", unique = true, nullable = false)
public String getCrp_code() {
return crp_code;
}
public void setCrp_code(String crp_code) {
this.crp_code = crp_code;
}
@Column(name="time_created", nullable = false)
public Date getTime_created() {
return time_created;
}
public void setTime_created(Date time_created) {
this.time_created = time_created;
}
@Column(name="last_update", nullable = false)
public Date getLast_update() {
return last_update;
}
public void setLast_update(Date last_update) {
this.last_update = last_update;
}
@Column(name="courier_name", nullable = false)
public String getCourier_name() {
return courier_name;
}
public void setCourier_name(String courier_name) {
this.courier_name = courier_name;
}
@Column(name="retry_count", nullable = false)
public Integer getRetry_count() {
return retry_count;
}
public void setRetry_count(Integer retry_count) {
this.retry_count = retry_count;
}
}
这是我的 DaoImpl
@Override
public void insertToCourierUploadQueue(String crp_code, String courier_name)
{
Query query = sessionFactory.getCurrentSession().createQuery("insert into CourierUploadQueue (:crp_code, 'PENDING', CURRENT_TIMESTAMP() , CURRENT_TIMESTAMP() , :courier_name, 0 )");
query.setParameter("crp_code", crp_code);
query.setParameter("courier_name", courier_name.toLowerCase());
query.executeUpdate();
}
我已经在我的数据库中创建了相应的 table。
我收到错误消息:
could not resolve property: : of: com.pooja.entity.CourierUploadQueue
你们能帮我解决这个问题吗?
INSERT INTO ... VALUES
在 HQL 中不受支持,因此出现错误。只有 INSERT INTO ... SELECT
。有关详细信息,请参阅文档的 DML-style operations 部分:
The pseudo-syntax for INSERT statements is: INSERT INTO EntityName properties_list select_statement
. Some points to note:
Only the INSERT INTO ... SELECT ...
form is supported; not the INSERT INTO ... VALUES ...
form.
如果你想执行 INSERT INTO ... VALUES ...
,你可能应该使用 SQL 和 session.createNativeQuery()
。
博胡斯拉夫是对的。 INSERT INTO ... HQL 不支持 VALUES。
相反,我这样做了:
public void insertToCourierUploadQueue(String crp_code, String courier_name){Session session1 = sessionFactory.openSession();
CourierUploadQueue courierUploadQueue = new CourierUploadQueue();
courierUploadQueue.setCrp_code(crp_code);
courierUploadQueue.setCourier_name(courier_name);
courierUploadQueue.setLast_update(new Date());
courierUploadQueue.setTime_created(new Date());
courierUploadQueue.setRetry_count(0);
courierUploadQueue.setStatus(CourierUploadQueueStatus.Status.PENDING);
session1.save(courierUploadQueue);
session1.close();}
这是我的实体 class :
@Entity
@Table(name = "courier_upload_queue")
public class CourierUploadQueue {
private int id;
private String crp_code;
private Status status;
private Date time_created;
private Date last_update;
private String courier_name;
private Integer retry_count;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@Enumerated(EnumType.STRING)
@Column(name= "status", nullable= false)
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
@Column(name= "crp_code", unique = true, nullable = false)
public String getCrp_code() {
return crp_code;
}
public void setCrp_code(String crp_code) {
this.crp_code = crp_code;
}
@Column(name="time_created", nullable = false)
public Date getTime_created() {
return time_created;
}
public void setTime_created(Date time_created) {
this.time_created = time_created;
}
@Column(name="last_update", nullable = false)
public Date getLast_update() {
return last_update;
}
public void setLast_update(Date last_update) {
this.last_update = last_update;
}
@Column(name="courier_name", nullable = false)
public String getCourier_name() {
return courier_name;
}
public void setCourier_name(String courier_name) {
this.courier_name = courier_name;
}
@Column(name="retry_count", nullable = false)
public Integer getRetry_count() {
return retry_count;
}
public void setRetry_count(Integer retry_count) {
this.retry_count = retry_count;
}
}
这是我的 DaoImpl
@Override
public void insertToCourierUploadQueue(String crp_code, String courier_name)
{
Query query = sessionFactory.getCurrentSession().createQuery("insert into CourierUploadQueue (:crp_code, 'PENDING', CURRENT_TIMESTAMP() , CURRENT_TIMESTAMP() , :courier_name, 0 )");
query.setParameter("crp_code", crp_code);
query.setParameter("courier_name", courier_name.toLowerCase());
query.executeUpdate();
}
我已经在我的数据库中创建了相应的 table。
我收到错误消息:
could not resolve property: : of: com.pooja.entity.CourierUploadQueue
你们能帮我解决这个问题吗?
INSERT INTO ... VALUES
在 HQL 中不受支持,因此出现错误。只有 INSERT INTO ... SELECT
。有关详细信息,请参阅文档的 DML-style operations 部分:
The pseudo-syntax for INSERT statements is:
INSERT INTO EntityName properties_list select_statement
. Some points to note:Only the
INSERT INTO ... SELECT ...
form is supported; not theINSERT INTO ... VALUES ...
form.
如果你想执行 INSERT INTO ... VALUES ...
,你可能应该使用 SQL 和 session.createNativeQuery()
。
博胡斯拉夫是对的。 INSERT INTO ... HQL 不支持 VALUES。
相反,我这样做了:
public void insertToCourierUploadQueue(String crp_code, String courier_name){Session session1 = sessionFactory.openSession();
CourierUploadQueue courierUploadQueue = new CourierUploadQueue();
courierUploadQueue.setCrp_code(crp_code);
courierUploadQueue.setCourier_name(courier_name);
courierUploadQueue.setLast_update(new Date());
courierUploadQueue.setTime_created(new Date());
courierUploadQueue.setRetry_count(0);
courierUploadQueue.setStatus(CourierUploadQueueStatus.Status.PENDING);
session1.save(courierUploadQueue);
session1.close();}