I need to map Oracle XMLType column to hibernate entity class. There is a working (and I think well-known) solution that involves implementing UserType; however, I cannot use it because requires importing Oracle xml parsers, which in turn causes many problems .
I'm ok with accessing value of xml column as a string and leave transformation to the code that manipulates entity, but I cannot find the way to read value from and write it to database. What I have tried so far:
- Declaring property in entity class as
String. Result - value is read asnull. If property is justSerializable, I get "cannot deserialize" exception. - Using
@Formulaannotation (CAST xmlCol as varchar2(1000)). Result - value is not stored - Using
@Loaderand puttingCASTinSELECT. That was the most promising attempt - value was read and stored successfully, but when it comes to loading collection of entities that contain xml column, I getnull(Hibernate doesn't use sql in@Loaderif underlying table isLEFT JOINed).
Another approach that I believe should work is to have xml column as String (for writing) plus dummy field for reading with @Formula; however, it looks like a dirty hack to me, and I'd prefer not to do so unless I have no choice.
Finally, the very last thing I can do is to change DB Schema (also more that 1 option, like view + triggers, column data type change), but this is not a good option for me either.
I wonder if I missed something or maybe there is a way to make (3) work?