I am trying to use the Spring Data JDBC and I cannot understand if there is a possibility to customize the column names of the embedded object (in JPA we use @AttributeOverrides
for this).
In my model I created a class Amount
they I would like to reuse in different types of objects.
public class Amount {
private BigDecimal value;
private String currency;
//getters, settes, contructors
}
I would like to save it like 2 embedded values in two tables: houses
and cars
.
In the table houses
I want the columns to be called house_price_value
and house_price_currency
. In the table cars
they should be called car_eval_value
and car_eval_currency
.
public class House {
@Id
Long id;
int numberOfRooms;
@Embedded
Amount amount;
//other attributes, getters, setters, constructors
}
public class Car {
@Id
Long id;
String model;
@Embedded
Amount amount;
//other attributes, getters, setters, constructors
}
The problem is that the annotation @Column
is applicable only to the attribute and should be set on the Amount
-class level. which makes this class not reusable.
In JPA I would have used this but in JDBC this annotation is not found:
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "house_price_value")),
@AttributeOverride(name = "currency", column = @Column(name = "house_price_currency"))
})
Don't I see another solution?