When working with Spring Boot R2DBC, am facing a situation whereby when writing raw queries using @Query
that contain INNER JOINs, some of the fields in all rows returned in the resulting Flux
have data but others are null. Yet when running the same query directly from the DB all fields are filled in which is what I would expect. What could be the problem? Column names and POJO/Bean names are an exact match, and are am mixture of camelCase
, all uppercase and all lowercase at both the DB level and in the code. E.g. in the below SQL:
@Query("SELECT" +
" i.inboundID, " +
" i.MSISDN," +
" i.message," +
" ms.shortDesc," +
//... other columns
" i.modifiedByUsername" +
" FROM inbound i " +
" JOIN messageStatuses ms on ms.statusCode = i.inboundStatus " +
" JOIN conversation cm on i.conversationID = cm.conversationID " +
//...some other SQL
" LIMIT :limit OFFSET :offset ")
Flux<MessageModel> findAllMessages(...)
And given the POJO below:
//getter and setter methods omitted
public class MessageModel
{
private Integer inboundID;
private String MSISDN;
private String message;
private String shortDesc;
...
private String modifiedByUsername;
}
... the fields MSISDN
and message
are the only columns that contain data when fetched via R2DBC, all the other columns will be empty. But all the columns will contain data when above SQL is extracted and executed directly on the database (MySQL). Any idea why that could be happening?
I managed to solve it by adding
@org.springframework.data.relational.core.mapping.Column
annotations to the Java model class column names. So now my POJOs have this structure: