Hi all,
I have following 3 tables in mysql db
[img]
mysql> select * from person;
+---------+--------+-----------------+-----------------+---------------------+----------+
| user_id | active | email | fullName | joined | password |
+---------+--------+-----------------+-----------------+---------------------+----------+
| bucky | 1 |
bucky@abc.com | Bucky Wall | 2017-01-30 12:43:46 | bucky |
| james | 1 |
james@abc.com | James Goedic | 2017-01-30 12:43:19 | james |
| praveen | 1 |
praveen@abc.com | Praveen Reddy S | 2017-01-30 12:37:40 | praveen |
| priya | 1 |
priya@abc.com | Priya Reddy | 2017-01-10 10:30:17 | priya |
+---------+--------+-----------------+-----------------+---------------------+----------+
4 rows in set (0.00 sec)
mysql> select * from tweet;
+----------+---------------------+----------------------------+---------+
| tweet_id | created | message | user_id |
+----------+---------------------+----------------------------+---------+
| 1 | 2017-01-30 12:45:37 | @Bucky!. Meet me in office | james |
| 2 | 2017-01-30 12:45:58 | @James!. How nare you? | praveen |
| 3 | 2017-01-30 12:46:10 | Hi, Every One | praveen |
| 4 | 2017-01-30 12:46:38 | @James: Hellow James | bucky |
| 5 | 2017-01-31 10:30:50 | This is Priya | priya |
+----------+---------------------+----------------------------+---------+
5 rows in set (0.00 sec)
mysql> select * from following;
+---------+--------------+
| user_id | following_id |
+---------+--------------+
| praveen | bucky |
| praveen | james |
+---------+--------------+
2 rows in set (0.00 sec)
[/img]
My Two Entity classes are
Person.java
Code:
@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>();
Tweet.java
Code:
@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;
Now I want to display messages of user praveen, and also all the messages mapped to praveen user in the following table. That means praveen user have 2 messages and his following users have 2 messages . Total 4 messages should be displayed. I really don't know how to retrieve this info using any technique in Hibernate. Please help me