siena
siena copied to clipboard
Unsupported type
I am using Siena with Scala and it complains of java.util.Calendar and scala.BigDecimal as unsupported types.
play.exceptions.UnexpectedException: Unexpected Error at play.Play.start(Play.java:525) at play.Play.detectChanges(Play.java:610) at play.Invoker$Invocation.init(Invoker.java:186) at Invocation.HTTP Request(Play!) Caused by: siena.SienaRestrictedApiException: Siena[db=h2][api=createColumn] Restricted Usage - Message:Unsupported type for field models.Metric.vendorFunds at siena.jdbc.ddl.DdlGenerator.createColumn(DdlGenerator.java:257) at siena.jdbc.ddl.DdlGenerator.addTable(DdlGenerator.java:77) at play.modules.siena.SienaPlugin.onApplicationStart(SienaPlugin.java:148) at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425) at play.Play.start(Play.java:495)
Yes
Calendar is not managed. Use classic Date instead. Calendar is a tool to manage time, not really a time container and also one the most catastrophic API in Java :D. I still wonder how we obtained this from a standardization process ;)
scala.BigDecimal is not managed as Siena is only Java for the time being (even if you can use it from Scala). But java.BigDecimal is managed and there is a doc in Siena github wiki about it. Moreover DDL (apache DDL) used by siena is a pure Java lib and no Scala there.
;-)
anyways, is there a way i could still use these types in my scala code and specify another overriding (SQL/ Java ? ) data type (like a @Column annotation) ? If possible, I wouldn't want to use Java in my code just because of Siena.
It's not trivial since this case hasn't been foreseen in Siena until now:) This is a case that should be imagined in the future to make Siena really compliant to Scala. Concerning the siena models, you must use java types because Siena doesn't know anything else, it's clear.
Then if you don't want to use any Java types in your Scala code, you should think of an implicit conversion. You write the corresponding class in pure Scala and write an implicit converter. It's only a workaround but I don't see any better way right now!
Pascal
tried, it doesn't like implicit conversions either for some reason :-(
Your implicit conversion must be completely external to the siena model. Siena can't analyze anything from Scala so if there are weird fields in the class, it will break for sure.
IMO, you must write a Java-style class for Siena and a mirrored pure-Scala class and a conversion from the Java-style class to the pure-Scala class.
ah! hmm, sure i'll change my code to java data types for now, thanks for the tip!
Sorry for that ;) Scala is gaining momentum, it's cool... I've been diving in it for a few month and I think it's a great evolution!
no problem! scala is cool indeed :-)