I have a table called entity relation. Which maps a grantee to its role. In a way a user can have multiple roles, and that a role can also have roles, For a small example:
+-----------+-----------+--+
| Grantee | Role | |
+-----------+-----------+--+
| SQL_User1 | SQL_Role1 | |
| SQL_User1 | SQL_Role2 | |
| SQL_Role1 | SQL_Role3 | |
| SQL_Role3 | SQL_Role4 | |
+-----------+-----------+--+
Now i want to create SQL query that find all the possible relationships of the entity. For example of the above:
SQL_User1 -> SQL_Role1, SQL_Role2, SQL_Role3, SQL_Role4
SQL_Role1 -> SQL_Role3
SQL_Role3 -> SQL_Role4
I know a way to do it in Java through recursion, But it feels to me like if there is an efficient way of doing it through a query it would be much faster.
Is there a good way of doing it?
Will it be faster than Java recursion implementation?
Thanks.