Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
spring-vaadin three tables joined
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.
I want to inform you that the problem is solved.
You just overwrite the toString() in the domain/model class.
For example,
@Entity
@Getter
@Setter
@Table(name = "groups")
public class Groups extends AbstractEntity {
@Basic
@Column(name = "groupname_x")
private String groupnameX;
@OneToMany(mappedBy = "groupsByGroupId")
private Collection<GroupAuthorities> groupAuthoritiesById;
@OneToMany(mappedBy = "groupsByGroupId")
private Collection<GroupMembers> groupMembersesById;
public Groups() {}
public Groups(String groupnameX, Long userChanged) {
this.groupnameX = groupnameX;
this.userChanged = userChanged;
}
@Override public String toString() { return id + "," + groupnameX; }}