4

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

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 + 单击目录正在打开实体,因此名称与查询中的实体匹配。

提前致谢。

4

1 回答 1

10

您可能忘记在persistence.xml. 看一看 :)

于 2013-02-07T01:10:05.670 回答