I want to create a table as below:
BLOCK_USER
************
ID
USER_ID, (ID for a single user how want to block other users below)
USER_ID, (A collection of IDS of users how are going to bee blocked by user above)
It means user A blocking uses B and C and …….
Is possible to do so:
@Entity
@Table(name = "BLOCK_USERS")
public class BlockUsers
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private int id;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="USER_ID")
private User wantToStop_id;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="USER_ID")
private Collection<User> thoseUsers_ids;
//getters and setters
}
You just need a one value in the ‘Blockee’ column, and to create a new row every time A Blocks someone. So:
So 5 has blocked 6, 7, 8, 10 and 9 has blocked 5.