MyBatis,无法通过构造函数以集合为参数创建对象
我有不可变的类,在实例化对象时遇到以下错误构造
表格
CREATE TABLE employee (
id varchar NOT NULL,
"name" varchar NOT NULL
)
CREATE TABLE muzimil.address (
id varchar NOT NULL,
street varchar NOT NULL,
city varchar NOT NULL,
emp_id varchar NULL
)
Java类
@Data
@Builder
@AllArgsConstructor
public class Employee {
private final String id;
private final String name;
private final List<Address> addresses;
}
@Data
@Builder
@AllArgsConstructor
public class Address {
private final String id;
private final String street;
private final String city;
private final String employeeId;
}
MyBatis:Mapper
<select id="getById" resultMap="employeeResultMap">
select
emp.id as employeeId,
emp.name as name,
aa.id as addressId,
aa.street as street,
aa.city as city
from employee emp
join address aa
on emp.id=aa.emp_id
where emp.id = #{id};
</select>
<resultMap id="employeeResultMap" type="Employee">
<constructor>
<idArg column="employeeId" javaType="String" name="id"/>
<arg column="name" javaType="String" name="name"/>
<arg resultMap="addressMap" name="addresses"/>
</constructor>
</resultMap>
<resultMap id="addressMap" type="java.util.List">
<association property="addresses" javaType="Address">
<collection property="address" javaType="java.util.ArrayList" ofType="Address">
<constructor>
<idArg column="addressId" javaType="String" name="id"/>
<arg column="street" javaType="String" name="street"/>
<arg column="city" javaType="String" name="city"/>
<arg column="employeeId" javaType="String" name="employeeId"/>
</constructor>
</collection>
</association>
</resultMap>
错误:
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.UnsupportedOperationException
### The error may exist in file [/Users/mchavak/Documents/muzimil/POC/postgres/ibatis/build/resources/main/mybatis/mapper/BrandMapper.xml]
### The error may involve com.muzimi.postgres.ibatis.EmployeeMapper.getById
### The error occurred while handling results
### SQL: select emp.id as employeeId, emp.name as name, aa.id as addressId, aa.street as street, aa.city as city from employee emp join address aa on emp.id=aa.emp_id where emp.id = ?;
### Cause: java.lang.UnsupportedOperationException