当我通过注释声明命名查询时,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);
}