【发布时间】:2012-09-18 14:57:13
【问题描述】:
当我通过注释声明命名查询时,Hibernate Session 无法找到它,但是当我放入 hbm.xml 时它工作正常。
这是一个遗留系统,其中所有休眠实体都通过 hbm.xml 定义,我正在慢慢尝试将其迁移到注释。
Is it possible to distribute hibernate metadata via both hbm.xml and annotations?
例外是
org.hibernate.MappingException: Named query not known: queryName
实体类是
@Entity
@NamedQueries({
@NamedQuery(name="queryName", queryString="from Product pro")
})
public class Product extends HibernateEntity
获取会话
SessionFactory hibernateSessionFactory = (SessionFactory) hibernateSessionFactories.get(targetDB);
if (hibernateSessionFactory != null)
{
session = hibernateSessionFactory.openSession(new HibernateEntityDifferenceInterceptor());
session.setFlushMode(FlushMode.COMMIT);
}
【问题讨论】:
-
看看如何配置 SessionFactory 很有用。
-
使用 SessionFactory 代码更新
-
仍然没有创建
SessionFactory的代码。 -
有了新发现,我意识到将 Annotation 和 hbm.xml 混合用于同一实体类的问题。我猜 Hibernate 不允许这样做。
标签: hibernate