java JPA 查询实体未映射错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14741769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JPA Query Entity not mapped error
提问by mt.uulu
Testing is not passing in the following code. Debugging shows the error is in the creation of the query.
测试未通过以下代码。调试显示错误在于查询的创建。
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 class:
实体类:
@Entity
@Table(name = "eb_catalog", uniqueConstraints=@UniqueConstraint(columnNames="name"))
public class Catalog implements ICatalog, Serializable {
and the query itself:
和查询本身:
TypedQuery<Catalog> query = em.createQuery(
"SELECT c FROM Catalog c WHERE c.name = :name", Catalog.class)
.setParameter("name", catName);
CTRL + click on Catalog is opening the entity, so the name matches the entity in the query.
CTRL + 单击 Catalog 正在打开实体,因此名称与查询中的实体相匹配。
thanks in advance.
提前致谢。
回答by Giovani Guizzo
You may have forgotten to map your entity class in the persistence.xml
.
Take a look :)
您可能忘记在persistence.xml
. 看一看 :)