You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are moving from using Java Pojo's as DTO's to records with the MyBatis framework.
The following two record types are used:
public record User(Integer cprid, String inlognaam, String upn, Boolean actief, String email, Locatie locatie, Collection<RoleExtra> rolesExtra) {}
public record RoleExtra(Role role) { }
The identifier of a user is the cprid.
Location and Role are simple enums.
Having the following query in myBatis:
<select id="getAllUsers" resultMap="suezUserResult">
SELECT g.inlognaam, g.cprid, g.upn, g.actief, g.email, g.locatie, grl.rol
FROM suez.gebruikers g
LEFT JOIN suez.gebruikers_rollen_link grl USING (cprid)
WHERE cprid = 107884
ORDER BY g.naam
</select>
When invoking getAllUsers I get an exception during instantiation of the User:
Caused by: java.lang.ClassCastException: Cannot cast amr.bi.elsalvador.domain.suez.RoleExtra to java.util.Collection
It seems that MyBatis is trying to make two instances of User for each role ROLE_PI and ROLE_PL (hence the argument type mismatch) instead of one instance using the set of roles.
What am I doing wrong?
The text was updated successfully, but these errors were encountered:
As I explained, in constructor-mapping, collection is supported only via nested select.
In other words, an immutable object whose constructor takes collections is not supported if you use JOIN (it's called "nested result" in our doc, by the way),
It is a known limitation.
The underlying technical difficulty is discussed in #101 if you are interested.
We are moving from using Java Pojo's as DTO's to records with the MyBatis framework.
The following two record types are used:
The identifier of a user is the cprid.
Location and Role are simple enums.
Having the following query in myBatis:
results in the tuples:
The resultmaps used:
When invoking getAllUsers I get an exception during instantiation of the User:
Caused by: java.lang.ClassCastException: Cannot cast amr.bi.elsalvador.domain.suez.RoleExtra to java.util.Collection
It seems that MyBatis is trying to make two instances of User for each role ROLE_PI and ROLE_PL (hence the argument type mismatch) instead of one instance using the set of roles.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: