2013-03-15 66 views
0

我有一個遺留Hibernate管理域這我現在想升級到一個Spring數據JPA環境。遺留Hibernate一個一對多映射使用JPA

Maven構建是成功的,當對遺留Hibernate DAO運行。

但是當我運行Maven構建對JPA實體管理器,我得到的是利用一個一對多映射的一個領域類的異常。

這裏是域類:

public class LinkCategory implements java.io.Serializable { 

    private Integer id; 
    private int version; 
    private String name; 
    private String description; 
    private Set<Link> links = new HashSet<Link>(); 

    public LinkCategory() { 
    } 

    public Integer getId() { 
     return this.id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    public int getVersion() { 
     return this.version; 
    } 

    public void setVersion(int version) { 
     this.version = version; 
    } 

    public String getName() { 
     return this.name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getDescription() { 
     return this.description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public Set<Link> getLinks() { 
     return this.links; 
    } 

    @SuppressWarnings("unused") 
    private void setLinks(Set<Link> links) { 
     this.links = links; 
    } 

    public void addLink(Link link) { 
     if (link.getLinkCategory() != this) { 
      if (link.getLinkCategory() != null) { 
       link.getLinkCategory().links.remove(link); 
      } 
      link.setLinkCategory(this); 
      this.links.add(link); 
     } 
    } 

    public void removeLink(Link link) { 
     if (link.getLinkCategory().getId() == this.getId() && this.getId() != null) { 
      link.setLinkCategory(null); 
      this.links.remove(link); 
     } 
    } 

} 

這裏是Hibernate映射:

<hibernate-mapping> 
    <class name="com.thalasoft.learnintouch.core.domain.LinkCategory" table="link_category" dynamic-insert="true" dynamic-update="true"> 
     <id name="id" type="java.lang.Integer"> 
      <column name="id" /> 
      <generator class="native"><param name="sequence">sq_id_link_category</param></generator> 
     </id> 
     <version name="version" type="int"> 
      <column name="version" not-null="true" /> 
     </version> 
     <property name="name" type="string"> 
      <column name="name" length="50" not-null="true" /> 
     </property> 
     <property name="description" type="string"> 
      <column name="description" not-null="false" /> 
     </property> 
     <set name="links" inverse="true" order-by="list_order" cascade="all"> 
      <key column="category_id" /> 
      <one-to-many class="com.thalasoft.learnintouch.core.domain.Link" /> 
     </set> 
    </class> 
</hibernate-mapping> 

我得到的錯誤是:org.hibernate作爲:

所致。 MappingException:無法確定類型 爲:java.util.Set中,在表:LinkCategory,爲列: [org.hibernate.mapping.Column(鏈接)]

我的休眠的版本是:3.6.9.Final 我的版本休眠JPA 2的是:1.0.1.Final 我的春天數據的版本JPA是:1.3.0.RELEASE

任何線索?

親切的問候,

+0

可以u顯示其他類的映射 – PSR

回答

0

我可以通過指定以下註解解決這一問題:

@OneToMany(mappedBy="linkCategory") 
private Collection<Link> links;