title: JPA(Hibernate) Map String to postgres XML datatype
body: <p>I'm trying to get the following setup to work:
  Wildfly 8.1.0 (comes with Hibernate as JPA implementation)
  Postgres 9.3 database</p>
  
  <p>I want to map a Java String to a colum of postgres' xml-type, but i get the error thet the column is of type "xml" while the expression is of type varchar.</p>
  
  <p>Most of the (maybe) solutions i found where database specific java classes, hibernate specific workarounds or just unanswered questions on Stackoverflow.</p>
  
  <p>I want to use the defined JPA-Methods to be able to switch to Mysql or SQLServer at will, even replace Widlfly+hibernate with glassfish or tomcat+openJPA without touching the code.</p>
  
  <p>Tweaking something in the Database however would be fine.</p>
  
  <p>I of course already did some research and found this post:
  <a href="http://www.pateldenish.com/2013/05/inserting-json-data-into-postgres-using-jdbc-driver.html" rel="nofollow">http://www.pateldenish.com/2013/05/inserting-json-data-into-postgres-using-jdbc-driver.html</a></p>
  
  <p>so i tried adding implicit casts for text and varchar:</p>
  
  <pre><code>create cast (varchar as xml) without function as implicit;
  create cast (text as xml) without function as implicit;
  </code></pre>
  
  <p>but postgres just says that these casts already exist. I verified this by inserting random Strings into the xml column, which worked fine. </p>
  
  <p>The Exception still occurs.</p>
  
  <p>thanks in advance for hints and directions,</p>
  
  <p>BillDoor</p>
  
  <p>UPDATE:</p>
  
  <p>I use postgres 9.3.1102.jdbc41</p>
  
  <p>the statements hibernate issues:</p>
  
  <pre><code>[PreparedStatement] setLong(3, 20)
  [PreparedStatement] setNull(2, -3)
  [PreparedStatement] setNull(1, 12)
  [Connection] prepareStatement(insert into testTable (xml, stuff, id) values (?, ?, ?))
  </code></pre>
  
  <p>fyi: stuff and xml are nullable, ID is primaryKey and the 20 is retrieved from a sequence correctly.</p>