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: Hibernate - Problem Mapping from a link table
PostPosted: Wed Jul 28, 2010 6:23 pm 
Newbie

Joined: Wed Jul 28, 2010 5:30 pm
Posts: 1
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


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.