title: Can I get the cascading ManyToOne relationship to lookup a child entity before it's saved?
body: <p>Lets say I have </p>
  
  <pre><code>@Entity
  @Table(name = "currency", uniqueConstraints = {})
  public class Currency {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column( name = "CURRENCY_ID")
      private Integer currencyId;
  
      @NaturalId
      @Column(name = "CURRENCY_CODE")
      private String code;
  }
  
  @Entity
  @Table(name = "price", uniqueConstraints ={})
  public class Price{
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "PRICE_ID")
      private Integer priceId;
  
      @Column(name= "AMOUNT")
      private Double amount;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @Cascade({CascadeType.ALL})
      @JoinColumn(name = "CURRENCY_ID", nullable = false)
      private Currency currency;
  }
  </code></pre>
  
  <p>And lets say I already have a currency in the currency table with the Currency Code of GBP.</p>
  
  <p>and then I'd like to do the following</p>
  
  <pre><code>Price p = new Price();
  p.setAmount(3.5);
  p.setCurrency(new Currency("GBP"));
  sessionFactory.getCurrentSession().save(p)
  </code></pre>
  
  <p>Currently I will get:</p>
  
  <pre><code>Caused by: org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation; UK_R07G412IP03G7P3N6P5O2PARG table: CURRENCY
  </code></pre>
  
  <p>Is it possible to configure Hibernate in such a way that it will try to lookup the currency with code GBP before trying to cascade the save operation, and if the currency with the code GBP already exists it will just set the Id of that currency on the price object?</p>