Postgres supports xml as is datatype for a column.
Hence I have a model that goes like this
@Entity
class StorageOfXml {
@Id
String id;
@Lob
@Column(columnDefinition="xml")
String myXml;
}
When I try to persist the model using entity manager, it gives me an error
StorageOfXml s = new StorageOfXml()
s.setId("sample");
s.setMyXml("<foo><bar></bar></foo>");
entityManager.persist(s)
Error is
Internal Exception: org.postgresql.util.PSQLException: ERROR: column "myXml" is of type xml but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
I notice that I need to cast the string to an xml format. However, I don't know where and how to cast it. How should I be able to persist and fetch this?