0

I'm using Scala's squeryl (version 0.9.6-RC1 with scala 2.10) and try to serialize my model to H2 database.

My model class has some string fields and some BigDecimal types (scala.BigDecimal).

I create database schema with Schema.create from my model classes, unfortunatelly squeryl always creates too small fields for BigDecimal, which leaves me with a value too long for column "MULTPZ DECIMAL(20, 16) NOT NULL": "1000000.0000000000000000 (23)";

Is this some kind of bug in squeryl? The original value is "1000000.0000" and is parsed into BigDecimal correctly.

I've tested the above situation, I've created a separate table with field defined as "DECIMAL(20, 20)" and in that case squeryl tries to insert "1000000.00000000000000000000 (27)"

Viktor Seifert
  • 636
  • 1
  • 7
  • 17
Marcin Cylke
  • 2,100
  • 2
  • 21
  • 40

1 Answers1

3

The easiest fix is to override the defaultSizeOfBigDecimal method in your Schema. It returns a tuple containing the length and scale for the numeric column that holds a BigDecimal. You can also set those values on a per-field basis with the @Column annotation.

Dave Whittaker
  • 3,102
  • 13
  • 14
  • Great, this worked. First thing I've tried was to set it and use the code with existing database, but that did not work. Then I've dropped the schema and recreated it with defaultSizeOfBigDecimal set. Why such behavior?? – Marcin Cylke Jul 01 '13 at 19:06
  • Squeryl does not handle schema evolutions. There just isn't a one-size-fits-all method for accomplishing that. Search the Squeryl list and you can find more information on that and suggestions for external libraries. – Dave Whittaker Jul 05 '13 at 14:56
  • But this was an initial schema creation. I've been creating a fresh db schema and new inserts into it failed immediately. – Marcin Cylke Jul 05 '13 at 20:24