title: What is the best way to deal with @OneToOne general type
body: <p>What is the best way to deal with something like (I know that this code would not work as the Object is not specified, It is just example):</p>
  
  <pre><code>@OneToOne
  private Object _reference;
  </code></pre>
  
  <p>where the variable _reference can be from different kind of documents (from different database table). One of the ideas I have is to keep:</p>
  
  <pre><code>private int _docId;
  private String _docTableReferenceName;
  </code></pre>
  
  <p>and then use reflection to get proper object, it would look something like:</p>
  
  <pre><code>session.get(Class.forName(_docTableReferenceName), _docId);
  </code></pre>
  
  <p>But this way has one drawback. It does not guarantee data consistency (as I need to remove the object when the _reference is removed). Sure I can work around with this by adding functions removeDocA, removeDocB but I wonder if maybe someone know more sophisticated way.
  I need to have the fast way to reference object in both sites (without searching in all table rows).</p>