将PostgreSql money数据类型映射到ORMLite [英] Map PostgreSql money data type to ORMLite

查看:186
本文介绍了将PostgreSql money数据类型映射到ORMLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在Java模型上为PostgreSQL货币类型定义什么类型的数据?

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

我知道我可以使用BigDecimal,但是它映射到varchar(255) PostgreSQL。

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

推荐答案

我认为@a_horse的评论提供了一些很好的信息,但我想我会添加一些其他的 ORMLite的详细信息。

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

您可以使用ORMLite的 BIG_DECIMAL_NUMERIC ,它将以 NUMERIC 的形式存储在Postgres中。您需要将其指定为:

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

这篇关于将PostgreSql money数据类型映射到ORMLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆