Let's take a following entity:
class Item{
@Id
Long id;
String name;
org.joda.money.Money price;
}
and a corresponding repository:
interface ItemRepository extends CrudRepository<Item, Long> {
}
Is it possible to persist Item in a relational DB table having amount and currency in separate columns without manually rewriting SQL queries offered by ItemRepository
?
DDL could be something like:
CREATE TABLE ITEM (
ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(255) NULL,
PRICE_AMOUNT DECIMAL NULL,
PRICE_CURRENCY VARCHAR(3) NULL
);
Storing Money in a single VARCHAR
column using custom @WritingConverter
and @ReadingConverter
is the closest I got, however this is not an option, as I need amount and currency clearly separated at the DB level.
I'm fine with replacing joda.money
in favor of javax.money
if that makes a difference, however I do not want to introduce my own custom type for handling money in domain layer.