HibernateSystemException:无法从Grails中的类[java.lang.Long]解析实体名称
我正在尝试使用带有Hibernate 3插件的Grails 2.4.3中的HibernateSystemException:无法从Grails中的类[java.lang.Long]解析实体名称,hibernate,grails,hql,gorm,criteria,Hibernate,Grails,Hql,Gorm,Criteria,我正在尝试使用带有Hibernate 3插件的Grails 2.4.3中的Model.executeQuery执行以下查询,其中Model是我的域类扩展CatalogeElement(带有tablePerHierarchy false集): 当我执行它时,我得到了以下异常: org.springframework.orm.hibernate3.HibernateSystemException: Unable to resolve entity name from Class [java.lang
Model.executeQuery
执行以下查询,其中Model
是我的域类扩展CatalogeElement
(带有tablePerHierarchy false
集):
当我执行它时,我得到了以下异常:
org.springframework.orm.hibernate3.HibernateSystemException: Unable to resolve entity name from Class [java.lang.Long] expected instance/subclass of [org.modelcatalogue.core.CatalogueElement]; nested exception is org.hibernate.HibernateException: Unable to resolve entity name from Class [java.lang.Long] expected instance/subclass of [org.modelcatalogue.core.CatalogueElement]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:708)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:414)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:416)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:348)
域类看起来类似于:
class CatalogueElement { String name }
class Model extends CatalogueElement { ... }
class Relationship {
CatalogueElement source
CatalogueElement destination
}
这个问题显然是由子查询语句引起的,好像我跳过了它们一样,一切都很好。实际上,在使用带有
DetachedCriteria
的子查询时,我也遇到了类似的错误。有人能解决这个问题吗?我不想先获取子查询并将结果传递给参数,因为它可能会在数千条记录中结束。事实上,问题出在:classifications
命名参数中,该参数是由Long
ID设置的,而不是由CatalogeElement
实体设置的。正确的查询是
select count(m)
from Model as m
where m.status = :status
and m not in (select r1.destination from Relationship r1 where r1.relationshipType = :type)
and m in (select r2.destination from Relationship r2 where r2.relationshipType = :classificationType and r2.source.id in :classifications)
看到你的域类的简化版本会很有帮助。我添加了域类和答案,因为我发现这个问题很愚蠢,但有可能其他人会像我一样愚蠢:-)
select count(m)
from Model as m
where m.status = :status
and m not in (select r1.destination from Relationship r1 where r1.relationshipType = :type)
and m in (select r2.destination from Relationship r2 where r2.relationshipType = :classificationType and r2.source.id in :classifications)