[using hibernate-3.1.1]
Can anyone confirm that it is not possible to pass a class name to a query as a parameter and have it automatically converted to the correct discriminator when using the Sql Server dialect?
While it appears to work when hard-coded into the hql, when passed as a parameter, it seems to just get handed off to the database as a raw string (which doesn't quite work when my discriminators are longs). I've spent the past several hours scouring the forums and the documentation as well as attempting to step through the code but I haven't been able to find a definitive answer yet. The closest post I found was
http://forum.hibernate.org/viewtopic.php?t=941125&highlight=discriminator+class+name+hql
The weird thing is, when I point at a MySQL database, the class name
is replaced by the discriminator.
Here's the code that works with MySQL but fails for SQL Server with a DataTruncation exception as it tries to cast the class name to a long:
Code:
String hql = "select me from ManagedElement me "
+ "where me.class = :cl and me.name = :nm";
Query query = session.createQuery(hql);
query.setParameter("cl", element.getClass(), Hibernate.CLASS);
query.setParameter("nm", element.getName(), Hibernate.STRING);
List<ManagedElement> list = query.list();
Thanks