Hibernate:为什么带有List <myclass>的@OneToMany失败?</myclass>

时间:2010-02-03 13:34:05

标签: hibernate list

我在这里与Hibernate3有一个奇怪的错误:

获得了一个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 - Class:

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>

任何人都可以解释我在这里看不到的东西吗?

2 个答案:

答案 0 :(得分:1)

配置XML中没有提及SoftwareLicenses。我猜Hibernate由于缺少SoftwarePrice条目而无法映射SoftwareLicenses,而这正在转化为无法映射SoftwareDescription和{{1}之间的关系}}

答案 1 :(得分:0)

好的......似乎这个错误非常愚蠢。我使用了来自Hibernate的Entity-Annotation而不是javax.persistence-one。解决。