gpt4 book ai didi

java - Hibernate org.hibernate.hql.ast.QuerySyntaxException 错误

转载 作者:行者123 更新时间:2023-12-02 00:25:06 25 4
gpt4 key购买 nike

我看到了一些与此相关的问题,但我无法找到解决我的问题的方法。

我声明了以下 PositionHistory 实体...

@Entity
@Table(name = "position_history")
@Cache (usage=CacheConcurrencyStrategy.READ_WRITE)
@AttributeOverride (name="id", column = @Column(name=PositionHistory.PRIMARY_KEY))
public class PositionHistory extends AbstractPersistable {

public static final String PRIMARY_KEY = "s_posn_history_id";
public static final String KEY = "positionHistory";
public static final String KEY_DATE = "date";
public static final String KEY_COMMENT = "comment";

// String field length definitions
public static final int LENGTH_COMMENTS = 1000;

// Instance Variables
private Date date;
private String comment;

@Column(name = "d_date", nullable = false)
public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

@Column(name = "t_comment", length = LENGTH_COMMENTS)
public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

// hashCode()
// equals()
// toString()
}

PositionHistoryDaoImp 中,我尝试删除一些行...

public void deletePositionHistory(Long positionId) {
getSession().createQuery("delete from position_history a where a.position_id=:id")
.setParameter("id", positionId).executeUpdate();
}

当我调用deletePositionHistory时,我收到以下错误...

ERROR a.g.q.d.v.s.c.CommandProcessorImpl:75 - org.hibernate.hql.ast.QuerySyntaxException: position_history is not mapped 

如您所见,该表已映射到 PositionHisotry 实体中,并且 PositionHistoryDaoImp 扩展了该实体。

我错过了什么或做错了什么?

非常感谢您的帮助。

谢谢。

<小时/>

位置实体...

@Entity
@Table(name = "position")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@AttributeOverride(name = "id", column = @Column(name = Position.PRIMARY_KEY))
public class Position extends AbstractPersistableEffective {
...
public static final String PRIMARY_KEY = "s_posn_id";
public static final String KEY_ID = "positionId";
private List<PositionHistory> history = new ArrayList<PositionHistory>();

...

@OneToMany(fetch = FetchType.LAZY)
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
@JoinColumn(name = Position.PRIMARY_KEY)
@IndexColumn(name = AbstractPersistable.INDEX_COLUMN)
public List<PositionHistory> getHistory() {
return history;
}

public void setHistory(List<PositionHistory> history) {
this.history = history;
}
}

最佳答案

您在查询中使用的是表名称,而不是实体名称。更改此:

getSession().createQuery("delete from position_history a where a.position_id=:id")

致:

getSession().createQuery("delete from PositionHistory a where a.id =:id")

关于java - Hibernate org.hibernate.hql.ast.QuerySyntaxException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10203918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com