0
JPA/Hibernate是否支持自定義類型?我認爲擴展BigDecimal足以讓Hibernate將我的類型視爲BigDecimal。這似乎並非如此。有什麼方法可以使這項工作?如果可能,我寧願避免使用@Embedded和@Embeddable。JPA/Hibernate是否支持自定義類型
類型:
public class Money extends BigDecimal {
public Money(String type) {
super(type);
}
}
實體:
@Entity
@Table(name = "Person")
public class Person implements java.io.Serializable {
private Integer id;
private Money inPocket;
@Column(name = "InPocket")
public Money getInPocket() {
return inPocket;
}
public void setInPocket(Money amount) {
this.amount = amount;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
當我嘗試這一點,我得到如下:
SEVERE: String or binary data would be truncated.
異常消息
: 在日誌中
org.hibernate.exception.DataException: could not insert: [Person]