[英]Legacy Hibernate one-to-many mapping with JPA
I have a legacy Hibernate managed domain which I'm now trying to upgrade to a Spring Data JPA environment. 我有一个旧的Hibernate托管域,现在我正在尝试将其升级到Spring Data JPA环境。
The Maven build is a success when run against the legacy Hibernate DAO. 当与传统的Hibernate DAO一起运行时,Maven构建是成功的。
But when I run the Maven build against the JPA entity manager, I get an exception on the one domain class that makes use of a one-to-many mapping. 但是,当我针对JPA实体管理器运行Maven构建时,我在使用一对多映射的一个域类上遇到了异常。
Here is the domain class: 这是域类:
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);
}
}
}
And here is the Hibernate mapping: 这是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>
The error I get is: 我得到的错误是:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: LinkCategory, for columns: [org.hibernate.mapping.Column(links)] 原因:org.hibernate.MappingException:无法确定类型:java.util.Set,在表:LinkCategory,用于列:[org.hibernate.mapping.Column(links)]
My version of Hibernate is: 3.6.9.Final My version of Hibernate JPA 2 is: 1.0.1.Final My version of Spring Data JPA is: 1.3.0.RELEASE 我的Hibernate版本是:3.6.9.Final我的Hibernate JPA 2版本是:1.0.1.Final我的Spring Data JPA版本是:1.3.0.RELEASE
Any clue ? 有什么线索吗?
Kind Regards, 亲切的问候,
I could solve the issue by specifying the following annotation: 我可以通过指定以下注释来解决此问题:
@OneToMany(mappedBy="linkCategory")
private Collection<Link> links;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.