Note that there are some explanatory texts on larger screens.

plurals
  1. POusing jaxb, hyperjaxb3, jpa2, jts, hibernate-spatial, postgis fails when hyperjaxb marks the JTS Point getter as @Transient
    text
    copied!<p>My coworkers lament my adherence to code generation, but I'm determined to prove this particular chain can be done. Examples below are simplified from my project (and thus untested as typed); I will create a test harness soon. Currently using hibernate 4.1.4, hibernate-spatial 1.1.1, hyperjaxb3-ejb-plugin 0.5.6.</p> <p>I start off with a schema that uses a Position element whose type is a simple string extension:</p> <pre><code> &lt;xsd:simpleType name="wktPoint"&gt; &lt;xsd:restriction base="xsd:string"&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; </code></pre> <p>I use bindings.xjb customizations to map my xmlType wktPoint to a JTS Point javaType using jaxb:javaType, since I will want to map the JTS Point field to a postgis geometry column:</p> <pre><code>&lt;jaxb:javaType name="com.vividsolutions.jts.geom.Point" xmlType="wktPoint" parseMethod="test.Reader.readWKTPoint" printMethod="test.Writer.writeWKTPoint" /&gt; </code></pre> <p>Later in the bindings.xjb, I start customizing the Position element using annox:annotation:</p> <pre><code>&lt;jaxb:bindings node="xsd:complexType[@name='MyType']//xsd:element[@name='Position']"&gt; &lt;annox:annotate target="getter"&gt; &lt;annox:annotate annox:class="javax.persistence.Basic"/&gt; &lt;annox:annotate annox:class="javax.persistence.Column" name="POSITION" columnDefinition="GEOMETRY"/&gt; &lt;annox:annotate annox:class="org.hibernate.annotations.Type" type="org.hibernatespatial.GeometryUserType"&gt; &lt;annox:annotate annox:field="parameters"&gt; &lt;annox:annotate annox:class="org.hibernate.annotations.Parameter" name="dialect" value="postgis"/&gt; &lt;/annox:annotate&gt; &lt;/annox:annotate&gt; &lt;/annox:annotate&gt; &lt;/jaxb:bindings&gt; </code></pre> <p>However, this produces the following getPosition method in MyType.java:</p> <pre><code>/** * Gets the value of the position property. * @return * possible object is * {@link String } */ @Transient @Basic @Column(columnDefinition = "GEOMETRY", name = "POSITION") @Type(parameters = { @Parameter(name = "dialect", value = "postgis") }, type = "org.hibernatespatial.GeometryUserType") public Point getPosition() { return position; } </code></pre> <p>So when I start up my application and jpa/hibernate starts initializing the tables, it skips the POSITION column altogether (since it got marked @Transient).</p> <p>How can I prevent @Transient from showing up? It seems I need to convince Hyperjaxb that we will be able to write the JTS Point type directly to the database (that's what all the @Type stuff is about, signaling that we want hibernatespatial to use the postgis dialect when reading and writing Positions). Any ideas on how to do that?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload