0

I have a sql server database with a table containing an xml column.

I'm begining with reactive programming with spring boot webflux / r2dbc.

When tying to retrieve data from the table I got an exception.

Caused by: java.lang.NullPointerException: value

It seems that the xml data type is not yet supported by the driver https://github.com/r2dbc/r2dbc-mssql

If I change the xml type to nvarchar(50) it's working. But I cannot change that.

So ... is there a solution or do I have to should i give up using r2dbc ?

I tried with using an explicit query in my repository like suggested by @Larnu. But do not forget to put an alias on the cast

@Query("select ..., cast(MyXML as nvarchar(max)) as myXmlAsString from ... where ...")

AND

use that alias in the "entity"

@Column("myXmlAsString") private String xml;
tweetysat
  • 2,187
  • 14
  • 38
  • 75
  • 2
    Why not `CONVERT`/`CAST` the data in your `SELECT` instead of the table's definition? (Though I would suggest using an `nvarchar(4000)` or `MAX`, as XML can be far longer than 50 characters.) – Thom A Jun 11 '21 at 11:36
  • Because the db already exists and cannot be changed. – tweetysat Jun 14 '21 at 05:48
  • That doesn't answer why you can't `CONVERT`/`CAST` the value in the **`SELECT`**. That answers why you can't change the design, and I didn't ask about that; XML data should be stored as `xml`. – Thom A Jun 14 '21 at 07:44
  • Ok I understand. So you mean to add in my repository an explicit sql instead of using the generated sql. I will try ... – tweetysat Jun 14 '21 at 11:31
  • Thanks for helping me @Larnu. The only remaining problem is that I have to put all the fields in the select statement. It could be long if there are lot of fields in the database. – tweetysat Jun 14 '21 at 12:15
  • A table has **columns** *not* "fields". And if you have lots of `xml` columns in a table table that sounds like a design flaw, if I am honest, however, the answer is to define those columns in your `SELECT` if you need them. If you don't want to write all of that out, then again, perhaps you should be looking at your design and that perhaps you don't need so many columns (due to denormalisation?). – Thom A Jun 14 '21 at 13:04

0 Answers0