我想将一个简单查询的结果集映射到我的域对象,但是当我使用into()
方法时,某些属性只是null
Result<DepartmentRecord> fetch = dsl.selectFrom(DEPARTMENT).fetch();
List<Department> collect = fetch.stream().map(f -> new Department(f.getId(), f.getName())).collect(Collectors.toList());
System.out.println("collect: " + collect);
// WORKS
// prints: collect: [Department [id=1, name=Mooh], Department [id=2, name=Mooh2]]
List<Department> into = fetch.into(Department.class);
System.out.println("into: " + into);
// DOESN'T WORK: name is null
// prints: into: [Department [id=1, name=null], Department [id=2, name=null]]
这是我的域对象/ JPA实体:
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
@Id
@GeneratedValue
private int id;
private String name;
}
我该怎么办?
使用Spring Boot 2.1.8,jOOQ 3.11.0,OpenJDK 11
答案 0 :(得分:1)
因为您具有默认的构造函数,并且属性的名称为dname,但是我假设数据库列的名称不同(例如,名称)。
如果默认构造函数可用,并且如果没有“ JPA列”批注,或者jOOQ在类路径上找不到javax.persistence API,则jOOQ将按照命名约定映射Record值:
https://www.jooq.org/javadoc/3.12.x/org.jooq/org/jooq/impl/DefaultRecordMapper.html