Hibernate ManyToMany HQL问题

时间:2017-01-31 07:59:17

标签: java mysql hibernate

我的MySql表:

db tables

我的两个实体类是

@Entity
public class Tweet {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO) 
    @Column(name="tweet_id")
    private int tweetId;
    private String message;
    private Date created;

    @ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
    @JoinColumn(name="user_id")
    private Person person;
    ...
}

@Entity
public class Person {

    @Id
    @Column(name = "user_id")
    private String userId;
    private String password;
    private String email;
    private String fullName;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "following", joinColumns = { @JoinColumn(name = "user_id") },
    inverseJoinColumns = { @JoinColumn(name = "following_id") })
    private List<Person> following = new ArrayList<Person>();
    ...
}

现在我想显示用户praveen的消息,以及下表中映射到praveen用户的所有消息。这意味着praveen用户有2条消息,而他的以下用户有2条消息。应显示总共4条消息。我真的不知道如何使用Hibernate中的任何技术检索此信息。请帮帮我

0 个答案:

没有答案