测试未传递以下代码。调试显示错误在于创建查询。
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打开实体,因此名称与查询中的实体匹配。
提前感谢。
答案 0 :(得分:9)
您可能忘记在persistence.xml
中映射您的实体类。
看一看:)