Reputation: 1701
I want to map a resultset of a simple query to my domain object but when I use the into()
method then some properties are just 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]]
Here is my domain object / JPA entity:
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
@Id
@GeneratedValue
private int id;
private String name;
}
What do I do wrong?
Using Spring Boot 2.1.8, jOOQ 3.11.0, OpenJDK 11
Upvotes: 3
Views: 1848
Reputation: 36133
Because you have a default constructor and the name of the property is dname but I the database column name is different I assume (e.g. name).
If a default constructor is available and if there are no JPA Column annotations, or jOOQ can't find the javax.persistence API on the classpath, jOOQ will map Record values by naming convention:
https://www.jooq.org/javadoc/3.12.x/org.jooq/org/jooq/impl/DefaultRecordMapper.html
Upvotes: 1