I have the following tables:
Query Table:
Code:
ID Name Schedule Retries Permissions
1 Test null 0 normal
2 Test_Schd 1001010 0 normal
Process Table:
Code:
ID Name Permissions
5 P_Test normal
6 P2_Test normal
7 P3_Test special
Link Table:
Code:
ID Query_ID Process_ID Location_ID Comment
21 1 5 8 null
22 1 6 8 scheduled update
23 1 7 8 changed timing information
The user who is using the system has only normal permissions & not special.
I have created the following hibernate mapping files:
...
<class name="Query"
table="queries">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="Schedule"/>
<property name="Retries"/>
<property name="Permissions"/>
</class>
...
...
<class name="Process"
table="processes">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="Permissions"/>
</class>
...
...
<class name="LinkTable"
table="linktable">
<id name="id">
<generator class="native"/>
</id>
<many-to-one name="Query"
column="query_id"/>
<many-to-one name="Process"
column="process_id"/>
...
</class>
...
I should add that I'm using an old version of hibernate (v 2.x) and so IIRC, lazy instantiation defaults to false. I have a simplified query inside a mapping file:
<query name="findLatestProcessForRequest">
<![CDATA[from LinkTable lt where ...]]>
</query>
The problem I'm having is that when this is executed as the user who only has 'normal' permissions, hibernate fetched back all the rows in the link table, but then throws an error when trying to access process 7 due to permissions i.e. special. It appears to hibernate as though the row in the process table does not exist.
I have tried modifying the many-to-one process relationship to lazily load i.e.:
<many-to-one name="Process"
column="process_id"
lazy="true"/>
This seems to fail, but for a different reason. The reason is that before the query is executed, I attempt to get the session from Hibernate with the following line:
HibernateUtil.currentSession()
After changing to lazy="true", this throws a ClassDefNotFound on this line.
The primary problem of course is how in general terms would you construct the hibernate mapping to allow for a link table to have foreign key references to other tables, but not to throw an exception if the record in the foreign table cannot be accessed due to not having the permissions of the foreign record?
Appreciate your assistance. Thanks,
Mark