title: How to test entities which have not null foreign key constraints
body: <p>I have a dozen of tables like <code>Product</code>, <code>Category</code>, <code>Customer</code>, <code>Order</code>, ...
  with <code>not null</code> relationships to one another. I created <code>ORM</code> and right now I am in the middle of tests.</p>
  <p>However I find it pretty tedious, because in order to test for example <code>Order</code> entity which has to belong to <code>Customer</code> (namely perform <code>persist</code> operation) I have to create <code>Customer</code> instance as well. Lets go further: because <code>Order</code> cannot exist separately to <code>Product</code> I have to create <code>Product</code> and add it to <code>Order</code>. <code>Product</code> has to be in some <code>Category</code>, and so on. So you can see a chain of mandatory relationships, which makes testing individual entity very difficult.</p>
  <p>Natural solution would be to defer constraint check to commit (Oracle):</p>
  <pre class="lang-sql prettyprint-override"><code>alter session set constraints=deferred;
  </code></pre>
  <p>However I found a piece of information that <code>Hibernate</code> doesn't care of deferring (<a href="https://hibernate.atlassian.net/browse/HHH-2248" rel="nofollow noreferrer">support for deferred constraint</a>).</p>
  <p>Does it mean, that persistence testing has to be so problematic or I can do it better/different?</p>
  <p>I believe that db constraints are sacred, so resigning from them, because hibernate does not support it sounds bad.</p>