title: Hibernate bi-directional access and illegal access to loading collection
body: <p>I have an issue with bidirectional access via a jointable, which works in one direction and not in the other. I've had to anonymise the definitions but hopefully everything significant is still there. The scenario is:</p>
  
  <p>MASTER is the main table which has a one-to-one mapping with two tables A_SECTION and B_SECTION which are sub-sections of the master record and all three share a common ID. This is an existing configuration which has worked for years. </p>
  
  <p>I've added a TIA_TIB_SHARE table which represents a many-many relationship between two rows in the MASTER table - this links the A_SECTION on one with the B_SECTION on another. Both relationships are identical as far as I can tell, but while access from a MASTER through an A_SECTION to another MASTER via the jointable works, if I access a different row from the B_SECTION side I get an "illegal access to loading collection" error. I've tried implementing lazy loading without any success.</p>
  
  <p>Can anyone provide any suggestions as to why this works in one direction and not in the other, or what steps I could take to diagnose this? I've extracted the relevant bits of the Hibernate mapping file below - all the mapping is in XML and there are no annotations used.</p>
  
  <p>Thanks in advance...</p>
  
  <pre><code>&lt;class name=”Master” table=”MASTER” where=”is_deleted=’N’”&gt;
  &lt;id name=”id” column=”ID” type=”long”&gt;
  &lt;generator class=”native” /&gt;
  &lt;/id&gt;
  &lt;one-to-one name=”sectionA” class=”SectionA” /&gt;
  &lt;one-to-one name=”sectionB” class=”SectionB” /&gt;
  
  &lt;/class&gt;
  &lt;class name=”SectionA” table=”A_SECTION” where=”is_deleted=’N’”&gt;
  &lt;id name=”id” column=”ID” type=”long”&gt;
  &lt;generator class=”native” /&gt;
  &lt;/id&gt;
  &lt;one-to-one name=”master” class=”Master”
  constrained=”true” /&gt;
  &lt;set name=”shared” sort=”natural”&gt;
  &lt;key column=”TIA_ID” /&gt;
  &lt;one-to-many class=”Share” /&gt;
  &lt;/set&gt;
  &lt;/class&gt;
  
  &lt;class name=”SectionB” table=”B_SECTION” where=”is_deleted=’N’”&gt;
  &lt;id name=”id” column=”ID” type=”long”&gt;
  &lt;generator class=”native” /&gt;
  &lt;/id&gt;
  &lt;one-to-one name=”master” class=”Master”
  constrained=”true” /&gt;
  &lt;set name=”sharing” sort=”natural”&gt;
  &lt;key column=”TIB_ID” /&gt;
  &lt;one-to-many class=”Share” /&gt;
  &lt;/set&gt;
  &lt;/class&gt;
  
  &lt;class name=”Share” table=”TIA_TIB_SHARE”&gt;
  &lt;id name=”id” column=”ID” type=”long”&gt;
  &lt;generator class=”native” /&gt;
  &lt;/id&gt;
  &lt;many-to-one name=”sharingA” class=”SectionA”
  cascade=”all” update=”true” insert=”true” column=”TIA_ID” /&gt;
  &lt;many-to-one name=”sharedB” class=”SectionB”
  cascade=”all” update=”true” insert=”true” column=”TIB_ID” /&gt;
  &lt;/class&gt;
  </code></pre>