I have a projection that's id needs to be a String, but in the entity it's coming from it's an Int (in a value class), is there any way to map the value to the projection? Here I can't really cast it to Column<String, String> because it's not and I can't make an extension either...
t
Toshihiro Nakamura
01/12/2024, 1:28 PM
Create a custom function.
Copy code
private fun cast(
expression: ColumnExpression<*, *>,
): ColumnExpression<String, String> {
val name = "cast"
val o1 = Operand.Column(expression)
return columnExpression(String::class, name, listOf(o1)) {
append("$name(")
visit(o1)
append(" as char)")
}
}
You can use the above function as follows.
Copy code
val query = QueryDsl.from(e)
.where { e.employeeName startsWith "S" }
.selectAsAddress(
version = e.version,
addressId = e.employeeId,
street = cast(e.version),
)