4

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?

2
  • I don't know the answer to your question... but are you actually doing create type money? could be a problem that money is a valid postgres type already (although I believe it's considered something you shouldn't use) Commented Aug 15, 2010 at 10:44
  • No it's just example. I use: CREATE DOMAIN "public"."price" AS numeric(12,2); PostgreSQL has solid built in support for user-defined data types, but I would like to know how to use them in Java. Commented Aug 15, 2010 at 11:42

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

OK. I'll use your references to find solution. Thanks for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.