We have a legacy application using Derby that we want to now work with both PostgreSQL and Derby.
Everything works fine on both except for this CLOB handling that needs to be different for this one class…
Switching the annotations as follows works, but we want one build for either DB.
For Derby
@MappedSuperclass
public class AbstractXmlLobBean extends StandardRootBean {
@Lob
@Column(name = "marshalledXml")
private String xml;
For PostgreSQL (we need it to use ‘text’)
@MappedSuperclass
public class AbstractXmlLobBean extends StandardRootBean {
@Lob
@Type(type = "org.hibernate.type.TextType")
@Column(name = "marshalledXml")
private String xml;
How can we accomplish this (using either annotations / mapping files / programatically)?
There wouldn’t be any equivalent in HBM for MappedSuperclass. You can use the Hibernate 3 documentation to find what was available back then. HBM mappings are deprecated anyway, so you are better off migrating to Hibernate 5 in the long run.
Migrating to Hibernate 5 is sort of out of the question. Like I said, this is an existing legacy app that needs to run on Postgres (cause it outgrew Derby on one install).
If I were to use the entity-mappings like you suggest, how do I register that xml mapping into the Hibernate configuration?
You can use the addResource method of the Configuration object.
However, you need to pass the relative path of the XML file as it’s located on the classptah. To see how that works, just add a breakpoint in this Hibernate test and run the test in debug mode.