These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: passing class as query parameter
PostPosted: Mon Mar 06, 2006 4:25 pm 
Newbie

Joined: Thu Mar 24, 2005 1:47 pm
Posts: 1
[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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.