org.hibernate.hql.ast.QuerySyntaxException:未映射实体类
我试图通过hibernate createQuery从映射器表中获取对象,但我遇到了这个错误 错误详细信息 下面是执行HQL查询的部分org.hibernate.hql.ast.QuerySyntaxException:未映射实体类,hibernate,hibernate-mapping,Hibernate,Hibernate Mapping,我试图通过hibernate createQuery从映射器表中获取对象,但我遇到了这个错误 错误详细信息 下面是执行HQL查询的部分 sessionFactory.getCurrentSession().createQuery("select u from UsersEventsPK u " + " where u.userid = :userid" + " and u.eventid = :eventid")
sessionFactory.getCurrentSession().createQuery("select u from UsersEventsPK u " +
" where u.userid = :userid" +
" and u.eventid = :eventid")
.setParameter("userid", userid)
.setParameter("eventid", eventid).uniqueResult();
下面是我的实体类
package com.cmc.aop.entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
public class UsersEventsPK implements Serializable {
@Basic(optional = false)
@Column(name = "userid", nullable = false)
private long userid;
@Basic(optional = false)
@Column(name = "eventid", nullable = false)
private long eventid;
public UsersEventsPK() {
}
public UsersEventsPK(long userid, long eventid) {
this.userid = userid;
this.eventid = eventid;
}
public long getUserid() {
return userid;
}
public void setUserid(long userid) {
this.userid = userid;
}
public long getEventid() {
return eventid;
}
public void setEventid(long eventid) {
this.eventid = eventid;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) userid;
hash += (int) eventid;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UsersEventsPK)) {
return false;
}
UsersEventsPK other = (UsersEventsPK) object;
if (this.userid != other.userid) {
return false;
}
if (this.eventid != other.eventid) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.cmc.aop.entity.UsersEventsPK[ userid=" + userid + ", eventid=" + eventid + " ]";
}
}
Hibernate.cfg.xml
请帮帮我
提前感谢UsersEventsPK是@EmbeddedAble。它不是映射实体..这就是错误的原因..尝试使用映射实体编写查询,其中UserEventsPK用作@Embedded或@EmbeddedIDThank。。。它正在工作。。。。
package com.cmc.aop.entity;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
public class UsersEventsPK implements Serializable {
@Basic(optional = false)
@Column(name = "userid", nullable = false)
private long userid;
@Basic(optional = false)
@Column(name = "eventid", nullable = false)
private long eventid;
public UsersEventsPK() {
}
public UsersEventsPK(long userid, long eventid) {
this.userid = userid;
this.eventid = eventid;
}
public long getUserid() {
return userid;
}
public void setUserid(long userid) {
this.userid = userid;
}
public long getEventid() {
return eventid;
}
public void setEventid(long eventid) {
this.eventid = eventid;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) userid;
hash += (int) eventid;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UsersEventsPK)) {
return false;
}
UsersEventsPK other = (UsersEventsPK) object;
if (this.userid != other.userid) {
return false;
}
if (this.eventid != other.eventid) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.cmc.aop.entity.UsersEventsPK[ userid=" + userid + ", eventid=" + eventid + " ]";
}
}
<hibernate-configuration>
<session-factory>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="com.cmc.aop.entity.UsersEvents" />
<mapping class="com.cmc.aop.entity.UsersEventsPK" />
</session-factory>
</hibernate-configuration>