0

我有一个班级评论:

@Entity
@Table(name = Constants.COMMENTS_TABLE)
@Audited
public class Comment {


@Column(name = "comment", nullable = false)
private String comment;

@ElementCollection(targetClass = CommentTopic.class)
@Enumerated(EnumType.STRING)
@Fetch(value = FetchMode.JOIN)
@CollectionTable(name = Constants.COMMENTS_TOPIC_JOIN_TABLE, joinColumns = @JoinColumn(name = "comment_id"))
@Column(name = "topic")
private Set<CommentTopic> commentTopics;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "comment_id", nullable = false)
private Long commentId;
}

保持评论类有效,但以下条件查询:

Criteria criteria = session.createCriteria(Comment.class)
         .add(Restrictions.eq("commentTopics", topic));

List<Comment> entries = criteria.list();

throws org.hibernate.exception.DataException:没有为参数 1 指定值。

这是构建的查询:

选择 this_.comment_id 作为comment1_0_0_,this_.comment 作为comment0_0_,commenttop2_.comment_id 作为comment1_0_2_,commenttop2_.topic 作为topic2_ 从评论中选择this_ left outer join comments_topic commenttop2_ on this_.comment_id=commenttop2_.comment_id where this_.comment_id=?

我是否使用了不正确的注释?

条件查询是否构造不正确?

4

1 回答 1

0

我将 CommentTopic 枚举放在 CommentTopicWrapper 类中。

我将 commentTopicsSet 的注释更新为:

@OneToMany(targetEntity = CommentTopicWrapper.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = Constants.COMMENTS_TOPIC_JOIN_TABLE, joinColumns = @JoinColumn(name = "comment_id"), inverseJoinColumns = @JoinColumn(name = "topic"))
private Set<CommentTopicWrapper> commentTopics;
于 2013-07-02T18:45:37.053 回答