title: Hibernate is mapping BigDecimal incorrectly
body: <p>I have two <code>@Entity</code>s, both with a <code>BigDecimal</code> field as follows:</p>
  
  <p>in one module:</p>
  
  <pre><code>@Entity
  @Table(name = "price_range")
  public class PriceRange extends AbstractPersistable&lt;Long&gt; {
      @Column(name = "price", precision = 19, scale = 4)
      private BigDecimal price;
  </code></pre>
  
  <p>and in another module:</p>
  
  <pre><code>@Entity
  @Table(name = "invoice_position")
  public class InvoicePosition extends AbstractPersistable&lt;Long&gt; {
      @Column(name = "optimized_cost", precision = 19, scale = 4)
      private BigDecimal optimizedCost;
  </code></pre>
  
  <p>both create tables in my database with the correct precision and scale values:</p>
  
  <pre><code>Table invoice_position
  ======================
  id,optimized_cost, ...
  ----------------------
  optimized_cost   decimal(19,4)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Table price_range
  =================
  id, price, ...
  -----------------
  price            decimal(19,4)
  </code></pre>
  
  <p>A Test Frontend saves the values correctly to the database.</p>
  
  <p>However in a unit test, one of the two returns a value with a rounding error:</p>
  
  <pre><code>0.520000000000000017763568394002504646778106689453125
  </code></pre>
  
  <p><em>(debugger says: sacle = 51 and precision = 0)</em></p>
  
  <p>while the other is working fine:</p>
  
  <pre><code>0.5200
  </code></pre>
  
  <p><em>(debugger says: scale = 4, precision = 4)</em></p>
  
  <p>Both values are retrieved from the database in the same way <em>(with an EntityManager building a CriteriaQuery with a CriteriaBuilder inside a JpaRepository)</em>:</p>
  
  <pre><code>List&lt;Invoice&gt; invoices = invoiceProvider.findAll();
  List&lt;PriceRange&gt; priceRanges = priceRangeProvider.findAll();
  </code></pre>
  
  <p>What could be the problem here? Or better: Where could it go wrong, if the Entity has the correct scale and precision and the database as well?</p>
  
  <p>I'm quite at a loss here, where can I look for the error?</p>