我正在尝试使用 Spring Data JDBC,但我无法理解是否可以自定义嵌入对象的列名(在 JPA 中我们@AttributeOverrides
用于此目的)。
在我的模型中,我创建了一个类Amount
,我想在不同类型的对象中重用它们。
public class Amount {
private BigDecimal value;
private String currency;
//getters, settes, contructors
}
我想将它保存为两个表中的 2 个嵌入值:houses
和cars
.
在表中houses
,我希望调用列house_price_value
和house_price_currency
。在表中cars
它们应该被称为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
}
问题是注解@Column
只适用于属性,应该在Amount
-class级别设置。这使得这个类不可重用。
在 JPA 中我会使用它,但在 JDBC 中找不到此注释:
@AttributeOverrides(value = {
@AttributeOverride(name = "value", column = @Column(name = "house_price_value")),
@AttributeOverride(name = "currency", column = @Column(name = "house_price_currency"))
})
我没有看到另一个解决方案吗?