I have below entity. When I use named query i give org.hibernate.MappingException: Named query not known: ServiceDataTO.findId. Why?
import javax.persistence.*;
@NamedQueries({
@NamedQuery(
name = ServiceDataTO.SELECT_ID,
query = "select serviceId from ServiceDataTO sd where sd.serviceType = :serviceType"
)}
)
@Entity
@Table(name = "MCI_SERVICE_DATA")
public class ServiceDataTO {
public static final String SELECT_ID = "ServiceDataTO.findId";
@Id
@Column(name = "SDT_ID")
private Long sdtId;
@Column(name = "SDT_SERVICE_ID")
private Long serviceId;
@Column(name = "SDT_SERVICE_TYPE")
private String serviceType;
}
client code:
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
List<Long> r = session.getNamedQuery(ServiceDataTO.SELECT_ID).setString("serviceType", serviceType).list();
How can I fix it?
I forgot add
ServiceDataTO
in hibernate config.