Hello! I've experienced some issues trying to implement polymorphic query in Hibernate.
The first thing I was trying
List<Class<? extends Entry>> classes = getClasses();
Query q = session.createQuery(" from " + Entry.class.getName() + " e where e.class in (:classes)");
q.setParametersList("classes", classes, Hibernate.CLASS);
return q.list();
The result was "Invalid character string format for type INTEGER."
The same result was even for the following:
Query q = session.createQuery(" from " + Entry.class.getName() + " e where e.class = ?");
q.setParameter(0, Entry.class, Hibernate.CLASS);
return q.list();
The only working code is the following:
Query q = session.createQuery(" from " + Entry.class.getName() + " e where e.class =" + Entry.class.getName());
return q.list();
Only in the last case Hibernate correctly converted class name to the discriminator value. Is it a bug in 3.1.3 or I am missing something? At least the second example worked great for me few years ago with Hibernate 2.1.6.
|