Hi,
I have three tables, Groupauthorities,Roles and Groups.
Groupauthorities has three columns eg. id, role_id and group_id.
Roles also has two columns eg. id, rolename_x and groups also has two columns eg. id, groupname_x
Groupauthorities has many-to-one relationship with roles and groups. The groupauthorities must show in vaadin table as below
ID Roles Name Group Name
1 ROLE_ADMIN Administrators
2 ROLE_USER Administrators
3 ROLE_USER Users
I googled for the solution how to use spring-data-jpa with many tables joined together and I found it as below
public interface MyRepository extends JpaRepository {
String sql = "SELECT t1.id as id, t2.role_x as roleX, t3.groupname_x as groupnameX " +
"FROM group_authorities as t1, roles as t2, groups as t3 " +
"WHERE t2.id = t1.role_id " +
“AND t3.id = t1.group_id”;
@Query(name = sql, nativeQuery = true)
List<Object> methodThatQueriesMultipleTables();
}
I use BeanItemContainer to load from the database to vaadin table. However, if I use this one as below, it would reject as it needs one class.
BeanItemContainer groupauthoritiesContainer = new BeanItemContainer<>(
GroupAuthorities.class, Roles.class, Groups.class
);
The only one thing I can think of is using Vaadin SQLContainer addon. Remember I use Vaadin Spring addon. It will work with these two addons.
I am not happy with these addons together as I like to keep the codes clean and easy to look at.
What is the solution of using BeanItemContainer or others?
Looking foward to hearing from you.