-->
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.  [ 3 posts ] 
Author Message
 Post subject: [HQL] discriminator-value in where-clause
PostPosted: Wed Mar 28, 2007 7:19 am 
Newbie

Joined: Sun Mar 11, 2007 11:31 am
Posts: 4
Hibernate version:
3.2.2

Mapping documents:
Code:
        <hibernate-mapping package="de.portal.permission">
            <class name="Rights" table="RIGHTS">
                <id name="id" unsaved-value="null">
                    <generator class="native"/>
                </id>
                <discriminator column="type" type="string" />
                <set name="rights" inverse="true" cascade="all-delete-orphan">
                    <key column="parent"/>
                    <one-to-many class="Rights"/>
                </set>
                <many-to-one name="parent" column="parent" cascade="save-update" class="Rights"/>
                <property name="name" type="string" unique="true" />
               
               
                <subclass name="User" discriminator-value="user">
                    <property name="password" type="string" />
     
                </subclass>     
               
                <subclass name="Group" discriminator-value="group">
                 
                </subclass>
            </class>
        </hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
            PersistenceManager.beginTransaction();
            Query query = session.createQuery("from Rights as r where parent.name=:name and r.class=Group").setParameter("name",groupName);
            List<Rights> result = query.list();
            PersistenceManager.commitTransaction();


Full stack trace of any exception that occurs:

javax.servlet.ServletException: cant't fetch members: unexpected token: Group near line 1, column 69 [from de.portal.permission.Rights as r where parent=null and r.class=Group]

Name and version of the database you are using:
MySQL 5.0.26

The generated SQL (show_sql=true):
none


So I want to fetch only the groups (=> type="group"). If I change r.class=Group to r.class=User all works well, but with "Group" as filter I get the above Exception.

Any idea why User works and Group doesn't?

Greets,
Ace


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 9:28 am 
Regular
Regular

Joined: Thu Dec 22, 2005 7:47 am
Posts: 62
Location: Czech Republic
hi

recently i also encountered problems with that, according to manual section 14.9. you are allowed to use class names in your .class expression, and it worked for me up to hibernate 3.1 (i used fully quallified class names).

since i upgraded to 3.2(.2) i was getting some exception (can reproduce but lazy right now) untill i rewritten the class expression with its sql value (ignoring the class name) -- ie. try to use .class=group.

i have in my mapping files for example

Code:
  <query name="cparty.topLevelCounterPartyComposites"><![CDATA[
select c from CounterPartyComposite as c
  where c.parentComponent is null
  and c.class = CounterPartyComposite
]]></query>


where CounterPartyComposite is the sql value the is filled in the column.

regards, martin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 9:50 am 
Newbie

Joined: Sun Mar 11, 2007 11:31 am
Posts: 4
Hm, k, so this seems to be bug....

It's working now with:

Code:
from Rights as r where r.parent.name=:name and r.class='group'


Thx!

Greets,
Ace


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

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.