开发者

Hibernate: Why @OneToMany with List<MyClass> fails?

开发者 https://www.devze.com 2022-12-19 14:26 出处:网络
I have a strange error with Hibernate3 here: Got a SoftwareDescription class, persisting it with the following field commented out works just fine:

I have a strange error with Hibernate3 here:

Got a SoftwareDescription class, persisting it with the following field commented out works just fine:

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

Got getters and setters for this field. When I try to persist a SoftwareDescription, I get this error:

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

This is my SoftwarePrice - Class:

package de.abelssoft.domain;
//...imports...开发者_如何学C

@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...
}

This is my Hibernate Config file:

<?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>

Can anyone explain what I'm not seeing here?


There's no mention of SoftwareLicenses in your config XML. I'm guessing that Hibernate is failing to map SoftwarePrice because of the lack of the SoftwareLicenses entry, and this is then translating into a failure to map the relation between SoftwareDescription and SoftwarePrice.


Okay ... it seems the error was quite stupid. I used the Entity-Annotation from Hibernate instead of the javax.persistence-one. Solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号