When I am declaring named query via annotations Hibernate Session is not able to find it but when I put into hbm.xml it works fine.
It is a legacy system where all the hibernate entities are defined via hbm.xml and I am slowly trying to migrate it to annotations.
Is it possible to distribute hibernate metadata via both hbm.xml and annotations?
Exception is
org.hibernate.MappingException: Named query not known: queryName
Entity Class is
@Entity
@NamedQueries({
@NamedQuery(name="queryName", queryString="from Product pro")
})
public class Product extends HibernateEntity
Getting the Session
SessionFactory hibernateSessionFactory = (SessionFactory) hibernateSessionFactories.get(targetDB);
if (hibernateSessionFactory != null)
{
session = hibernateSessionFactory.openSession(new HibernateEntityDifferenceInterceptor());
session.setFlushMode(FlushMode.COMMIT);
}
With Spring support it’s definitely possible, so if you don’t use Spring, you can look at the sources inside of it and figure out how it was implemented there.