-->
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: Criteria restriction with native sql mapping entity property
PostPosted: Fri Apr 01, 2005 5:10 pm 
Newbie

Joined: Tue Mar 22, 2005 3:50 pm
Posts: 4
The short question, how do you get the database column name of the id property of a given Hibernate entity.

The long question...

Here is my setup:

Hibernate version:

3.0

Mapping documents:

Code:
<class name="ACSObject" table="acs_objects">
    <id name="ID" type="int" column="object_id"/>
</class>


Code:
<joined-subclass name="Party"
        table="parties"
        extends="ACSObject">
    <key column="party_id"/>
</joined-subclass>


Code:
<joined-subclass name="User"
        table="users"
        extends="Party">
    <key column="user_id"/>
</joined-subclass>


Code between sessionFactory.openSession() and session.close():

Code:
Criteria privQuery = m_session
    .createCriteria(User.class)
    .add(Restrictions.sqlRestriction(
        "exists(" +
        "   select 1 as permission_p" +
        "   from dnm_object_1_granted_context dogc," +
        "        dnm_granted_context dgc," +
        "        dnm_permissions dp," +
        "        dnm_group_membership dgm" +
        "   where dogc.pd_context_id = dgc.pd_object_id" +
        "         and dgc.pd_context_id = dp.pd_object_id" +
        "         and dgm.pd_member_id = ?" +
        "         and dp.pd_grantee_id = dgm.pd_group_id" +
        "         and dogc.pd_object_id = {alias.ID}" +
        "         and " + privCol + " = 1" +
        ")",
        new Object[] {new Integer(4)},
        new Type[] {new IntegerType()}
));


This code doesn't work but it demonstrates what I want to do. I would like to add a restriction where the exists filter maps to the ID column of the hibernate entity, in this case User.ID

The query would look something like this:

Code:
select this_.user_id as object1_1_,
       ...
from users this_ inner join
      parties this_1_ on this_.user_id=this_1_.party_id inner join
      acs_objects this_2_ on this_.user_id=this_2_.object_id
where exists(
      select 1 as permission_p
      from dnm_object_1_granted_context dogc,
           dnm_granted_context dgc,
           dnm_permissions dp,
           dnm_group_membership dgm
      where dogc.pd_context_id = dgc.pd_object_id
            and dgc.pd_context_id = dp.pd_object_id
            and dgm.pd_member_id = 4
            and dp.pd_grantee_id = dgm.pd_group_id
            and dogc.pd_object_id = this_.user_id
            and pd_priv_05 = 1
)



Any suggestions?


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.