使用@OneToMany或@ManyToMany定位未映射的类

时间:2016-06-25 23:26:43

标签: java spring hibernate hibernate-annotations

我已经尝试了其他问题中描述的解决方案,但没有一个能够奏效,我不知道发生了什么,这里是豆子:

let bufferList: AudioBufferList
let packetDescriptions: [AudioStreamPacketDescription]
var newBuffer: CMSampleBuffer?

CMAudioSampleBufferCreateWithPacketDescriptions(
  kCFAllocatorDefault, // allocator
  nil, // dataBuffer
  false, // dataReady
  nil, // makeDataReadyCallback
  nil, // makeDataReadyRefCon
  formatDescription, // formatDescription
  Int(bufferList.mNumberBuffers), // numSamples
  CMSampleBufferGetPresentationTimeStamp(buffer), // sbufPTS (first PTS)
  &packetDescriptions, // packetDescriptions
  &newBuffer)

这是抛出的Hibernate异常:

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; }
}

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

尝试从private Set<Long> favoriteProducts;

中删除@OneToMany注释

您已使用@ElementCollection定义了该集合,并且@OneToMany是为实体保留的(java.lang.Long不是)。

您可以在此处找到一些信息:https://en.wikibooks.org/wiki/Java_Persistence/ElementCollection