The problem is not really with the column type, at least that's not what JPA is complaining about for now, the problem is that JPA doesn't know how to map a Price
type which is not one of the basic supported type, nor an Entity.
2.1.1 Persistent Fields and Properties
The persistent fields or properties of
an entity may be of the following
types: Java primitive types;
java.lang.String
; other Java
serializable types (including
wrappers of the primitive types,
java.math.BigInteger
,
java.math.BigDecimal
,
java.util.Date
,
java.util.Calendar
,
java.sql.Date
, java.sql.Time
,
java.sql.Timestamp
, user-defined
serializable types, byte[]
,
Byte[]
, char[]
, and Character[]
; enums; entity
types and/or collections of entity types; and embeddable classes (see section 2.1.5).
With standard JPA, try to use the Embeddable
and the Embedded
annotations:
@Embeddable
public class Price {
private BigDecimal amount;
...
}
and then in your entity:
@Embedded
@AttributeOverrides({
@AttributeOverride(name="amount", column=@Column(name="AMOUNT"))
})
public Price getPrice() { ... }
The other option would be to use a TransformationMapping
(EclipseLink specific).
References
- JPA 1.0 specification
- 2.1.5 Embeddable Classes
- 2.1.6 Mapping Defaults for Non-Relationship Fields or Properties
- 9.1.34 Embeddable Annotation
- 9.1.35 Embedded Annotation