Reputation: 5246
I have seen a few questions about this but I am unable to derive a solution to my problem.
I have the following PositionHistory
entity declared...
@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()
}
And in the PositionHistoryDaoImp
I am trying to delete some rows...
public void deletePositionHistory(Long positionId) {
getSession().createQuery("delete from position_history a where a.position_id=:id")
.setParameter("id", positionId).executeUpdate();
}
When I call deletePositionHistory
I get the following error...
ERROR a.g.q.d.v.s.c.CommandProcessorImpl:75 - org.hibernate.hql.ast.QuerySyntaxException: position_history is not mapped
As you can see, the table is already mapped in the PositionHisotry
Entity and the PositionHistoryDaoImp
extends the entity.
What am I missing or doing wrong?
Your help is very much appreciated.
Thank you.
Position
Entity...
@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;
}
}
Upvotes: 0
Views: 1004
Reputation: 69
Change the hibernate.query.factory_class property in hibernate.cfg.xml
file as show below....I hope it would help you..
<property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
Upvotes: 1
Reputation: 80593
You are using the table name in your query, as opposed to the entity name. Change this:
getSession().createQuery("delete from position_history a where a.position_id=:id")
To:
getSession().createQuery("delete from PositionHistory a where a.id =:id")
Upvotes: 2