【发布时间】:2016-06-25 23:26:43
【问题描述】:
我尝试了其他问题中描述的解决方案,但没有一个有效,我不知道发生了什么,这是 bean:
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table( name = "USER_ACTIVITY" )
public class UserActivity
{
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
@Column( name = "ID" )
private long id;
@ElementCollection( targetClass = Long.class )
@OneToMany( cascade = CascadeType.ALL )
@Column( name = "FAVORITE_PRODUCTS" )
private Set<Long> favoriteProducts;
public UserActivity() {}
public Set<Long> getFavoriteProducts() { return favoriteProducts; }}
public void setFavoriteProducts( Set<Long> favoriteProducts ) { this.favoriteProducts = favoriteProducts; }
}
这是引发的 Hibernate 异常:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: es.sidelab.cuokawebscraperrestserver.beans.UserActivity.favoriteProducts[java.lang.Long]
知道为什么会这样吗?
【问题讨论】:
-
发生这种情况是因为关系的目标不是映射类。
标签: java spring hibernate hibernate-annotations