Workaround for Hibernate relationships and SmartGWT RESTDataSources
I'm lost with the way I have to implement a ManyToMany relationship defined in Hibernate. In the client-side we're using SmartGWT LGPL version with RESTDataSources working fine against some back-end webservices.
The relationship is made between a typical Role and Permissions. In Rol.class:
... @ManyToMany @JoinTable(name = "ROL_PERMISO", joinColumns = @JoinColumn(name = "ROL_ID"), inverseJoinColumns = @JoinColumn(name = "PERMISO_ID")) private Set<Permiso> permisos; ...
In the client side I have two 'views'. The first one is for permission's management. The another one is for role management, which has a ListGrid showing roles and a DynamicForm with a permissions CheckBoxTree to select the permissions associated to the role, and other fields like name and description.
How I stablish the relationship between roles and permissions in the DataSources? Any recommended workaround?
After searching on it I've solved that using nested DataSource:
In Rol DataSource:
... // One to Many relationship DataSourceField permisos = new DataSourceField("permisos", FieldType.TEXT, locale.permisos()); permisos.setTypeAsDataSource(PermisoDS.getInstance()); ...
The key is create a DatSourceField and set the type as DataSource. And then, for accessing the data you can use getAttributeAsRecordArray("permisos") in a record of Rol DataSource
Hope this help someone!