创建EntityManagerFactory实例后,我收到错误消息:...Exception Description: Predeployment of PersistenceUnit [aPU] failed.Internal Exception: Exception [EclipseLink-7157] (Eclipse Persistence Services ...
创建EntityManagerFactory实例后,我收到错误消息:
...
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].
...
列价格是域类型(例如:CREATE TYPE MONEY AS NUMERIC(10,2)FINAL).
如何使用Domain或Struct PostgreSQL类型? JPA可以吗?
解决方法:
问题不在于列类型,至少这不是JPA现在抱怨的问题,问题是JPA不知道如何映射不是基本支持类型之一的Price类型,也不知道实体.
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[], andCharacter[]; enums; entity
types and/or collections of entity types; and embeddable classes (see section 2.1.5).
使用标准JPA,尝试使用Embeddable和Embedded注释:
@Embeddable
public class Price {
private BigDecimal amount;
...
}
然后在你的实体中:
@Embedded
@AttributeOverrides({
@AttributeOverride(name="amount", column=@Column(name="AMOUNT"))
})
public Price getPrice() { ... }
另一种选择是使用TransformationMapping(特定于EclipseLink).
参考
> JPA 1.0规范
> 2.1.5可嵌入类
> 2.1.6映射非关系字段或属性的默认值
> 9.1.34可嵌入注释
> 9.1.35嵌入式注释
本文标题为:在Java中使用PostgreSQL Domain和Struct类型
基础教程推荐
- Java实现树形List与扁平List互转的示例代码 2023-07-15
- SpringBoot分页的实现与long型id精度丢失问题的解决方案介绍 2023-06-10
- 关于Guava缓存详解及使用说明 2023-06-24
- Springboot实例讲解实现宠物医院管理系统流程 2022-12-06
- jsp页面显示数据库的数据信息表 2023-08-02
- Java8如何利用Lambda快速生成map、多层嵌套map 2023-06-01
- Java8新特性Optional类及新时间日期API示例详解 2023-07-01
- 如何在SpringBoot中使用Spring-AOP实现接口鉴权 2023-06-01
- Java设计模式初识之备忘录模式详解 2023-07-01
- jsp输出金字塔的简单实例 2023-08-03
