views:

48

answers:

1

After creating EntityManagerFactory instance, I receive error message:

...
Exception Description: Predeployment of PersistenceUnit [aPU] failed.
Internal Exception: Exception [EclipseLink-7157] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class Table] must use a @JoinColumn instead of @Column to map its relationship attribute [Price].
...

Column Price is Domain type (example: CREATE TYPE MONEY AS NUMERIC(10,2) FINAL).

How to use Domain or Struct PostgreSQL types? Is it possible with JPA?

+1  A: 

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
Pascal Thivent
OK. I'll use your references to find solution.Thanks for help.
Ilke