2010-02-03 76 views
2

我有一個奇怪的錯誤與Hibernate3的位置:休眠:爲什麼@OneToMany與列表<MyClass>失敗?

得到了SoftwareDescription類,有以下字段註釋掉的作品就好了堅持它:

@OneToMany 
@JoinColumn(name = "id") 
private List<SoftwarePrice> prices = new ArrayList<SoftwarePrice>(); 

得到了這一領域的getter和setter。當我嘗試堅持一個SoftwareDescription,我得到這個錯誤:

"Use of @OneToMany or @ManyToMany targeting an unmapped class: de.abelssoft.domain.SoftwareDescription.prices[de.abelssoft.domain.SoftwarePrice]" 

這是我SoftwarePrice - 類:

package de.abelssoft.domain; 
//...imports... 

@Entity 
public class SoftwarePrice implements Serializable{ 

private static final long serialVersionUID = 8771685731600495299L; 

public SoftwarePrice(){} 

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
private long id; 

@Lob 
private Currency currency = null; 

private SoftwareLicenses license = null; 

private double price = 0.0; 

//... setters getters... 
} 

這是我的Hibernate的配置文件:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory name="MyHibernateSessionFactory"> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 

     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> 
     <property name="hibernate.connection.password">root</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> 
     <property name="current_session_context_class">thread</property> 
     <property name="show_sql">false</property> 
    <property name="hbm2ddl.auto">update</property> 
    <mapping class="de.abelssoft.domain.SoftwareDescription" /> 
    <mapping class="de.abelssoft.domain.SoftwareCategory" /> 
    <mapping class="de.abelssoft.domain.SoftwarePrice" /> 
    <mapping class="de.abelssoft.domain.SoftwareDescriptionText" /> 
    </session-factory> 
</hibernate-configuration> 

人解釋我在這裏沒有看到什麼?

回答

1

在配置XML中沒有提及SoftwareLicenses。我猜測Hibernate無法映射SoftwarePrice,因爲缺少SoftwareLicenses條目,這會導致無法映射SoftwareDescriptionSoftwarePrice之間的關係。

+0

Uhm。好主意,忘了提,但這只是一個枚舉。我在SoftwareDescription.class中獲得了該字段,該字段保持得很好,並且還針對枚舉: private de.abelssoft.domain.SoftwareArchives softwareArchive; – Akku 2010-02-03 13:53:17

0

好吧......看起來這個錯誤相當愚蠢。我使用Hibernate的Entity-Annotation而不是javax.persistence-one。解決了。