Map PostgreSql money data type to ORMLite

房东的猫 提交于 2020-01-06 14:28:02

问题


What type of data I should define on my java model for PostgreSQL money type?

I know I could use BigDecimal, but it map to varchar(255) on PostgreSQL.


回答1:


I think that @a_horse's comment provides some good information but I thought I'd add some additional ORMLite's specific details.

You could use ORMLite's BIG_DECIMAL_NUMERIC which will store it in Postgres as NUMERIC. You'll need to specify it as:

@DatabaseFiled(dataType = BIG_DECIMAL_NUMERIC)
BigDecimal number;

If you are set on using the money type, then you can define your own custom persister. You can date a look at the documentation that front:

http://ormlite.com/docs/custom-persister

There is also an example project with code which shows how to define a data persister for your custom type:

http://ormlite.com/docs/data-persister-example



来源:https://stackoverflow.com/questions/9965829/map-postgresql-money-data-type-to-ormlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!