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?