JPA查询实体未映射错误

时间:2013-02-07 00:55:10

标签: java jpa hql jpql

测试未传递以下代码。调试显示错误在于创建查询。

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Catalog is not mapped [SELECT c FROM Catalog c WHERE c.name = :name]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1347)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1288)

实体类:

@Entity
@Table(name = "eb_catalog", uniqueConstraints=@UniqueConstraint(columnNames="name"))
public class Catalog implements ICatalog, Serializable {

和查询本身:

TypedQuery<Catalog> query = em.createQuery(
"SELECT c FROM Catalog c WHERE c.name = :name", Catalog.class)
.setParameter("name", catName);

CTRL +单击Catalog打开实体,因此名称与查询中的实体匹配。

提前感谢。

1 个答案:

答案 0 :(得分:9)

您可能忘记在persistence.xml中映射您的实体类。 看一看:)