2013-04-09 41 views
0

我不能運行我的項目,因爲我得到這個錯誤:「在關係屬性」中使用非實體[類java.lang.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; 

我在做什麼錯在這裏?

回答

4

@OneToMany映射的目標必須是有效的JPA實體。在你的情況下,Double類肯定不是一個實體類,因此是錯誤信息。如果您只是想存儲值的集合,請考慮使用@ElementCollection

@ElementCollection 
private Collection<Double> wegCategoriePrijzen; 
+0

非常感謝!這也適用於ArrayList嗎? – 2013-04-09 20:31:12

+1

理論上是,但請記住某些提供程序(如Hibernate)無法在同一個實體對象內映射多個列表。所以它更安全地使用集合或集合。 – Perception 2013-04-09 20:33:45

相關問題