当我通过注释声明命名查询时,Hibernate Session无法找到它但是当我放入hbm.xml时它工作正常。
这是一个遗留系统,其中所有hibernate实体都是通过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);
}