创建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类型
基础教程推荐
- Reactive反应式编程及使用介绍 2022-11-05
- Springboot内嵌tomcat应用原理深入分析 2023-06-01
- spring jpa设置多个主键遇到的小坑及解决 2023-01-02
- Java阻塞队列必看类:BlockingQueue快速了解大体框架和实现思路 2023-06-30
- Mybatis-Plus中updateById方法不能更新空值问题解决 2023-04-12
- 详解Java的构造方法及类的初始化 2023-04-17
- Springboot集成kafka高级应用实战分享 2023-04-12
- Java分布式服务框架Dubbo介绍 2023-02-10
- Mybatis-Plus实现多主键批量保存及更新详情 2023-05-24
- 解决spring.thymeleaf.cache=false不起作用的问题 2022-12-27