“在关系属性中使用非实体[类java.lang.Double]作为目标实体”,我该怎么办?

时间:2013-04-09 20:17:20

标签: java-ee jpa glassfish persistence double

我无法运行我的项目,因为我收到此错误:

Exception Description: Predeployment of PersistenceUnit [RekeningAdministratiePU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class domain.Regio] uses a non-entity [class java.lang.Double] as target entity in the relationship attribute [field wegCategoriePrijzen].
javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [RekeningAdministratiePU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class domain.Regio] uses a non-entity [class java.lang.Double] as target entity in the relationship attribute [field wegCategoriePrijzen].

我的实体类看起来像这样

@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
private String naam;
@OneToMany(cascade= { CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
private Collection<Locatie> locaties;
@OneToMany(cascade= { CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
private Collection<Double> autoCategorieMutaties;
@OneToMany(cascade= { CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
private Collection<Double> wegCategoriePrijzen;
private Double binnenrijTarief;

我在这里做错了什么?

1 个答案:

答案 0 :(得分:5)

@ OneToMany映射的目标必须是有效的JPA实体。在您的情况下,类Double绝对不是实体类,因此是错误消息。如果您只想存储值集合,请考虑使用@ ElementCollection

@ElementCollection
private Collection<Double> wegCategoriePrijzen;