创建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类型
- springboot集成KoTime的配置过程 2023-01-02
- Gateway网关源码解析 2023-03-22
- 利用Java连接Hadoop进行编程 2023-02-05
- 教你使用eclipse 搭建Swt 环境的全过程 2023-08-11
- SpringBoot整合Redis实现常用功能超详细过程 2023-04-18
- Spring @Cacheable指定失效时间实例 2023-08-10
- SpringBoot异常错误页面实现方法介绍 2023-05-14
- SpringBoot整合Thymeleaf与FreeMarker视图层技术 2023-04-12
- jsp图片效果大全(图像震动效果、闪烁效果、自动切换图像) 2023-08-02
- springboot返回图片流的实现示例 2023-04-12