创建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中的OPT算法实现方式 2023-02-27
- JSP自定义标签案例分析 2023-08-03
- 关于SpringBoot的异常回滚和事务的使用详解 2023-07-15
- 详解Spring系列之@ComponentScan自动扫描组件 2023-01-03
- java开发使用StringUtils.split避坑详解 2023-07-01
- SpringBatch从入门到精通之StepScope作用域和用法详解 2022-12-02
- SpringBoot实现过滤器拦截器的耗时对比 2023-02-04
- struts json 类型异常返回到js弹框问题解决办法 2023-08-01
- java性能优化四种常见垃圾收集器汇总 2023-02-26
- Spring AOP事务管理的示例详解 2023-01-17