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
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI'm looking closer at hyperjaxb3, and I've found that my Position's FieldOutline is neither basic nor complex (and thus is marked @Transient) because of the jaxb:javaType customization. Since the customization succeeds, the FieldOutline's JType shows up as com.sun.codemodel.JDirectClass(Point) and so I remain stuck...
      singulars
    2. COWhy are you messing around with xml to generate code? You should do it the other way around, annotate the code and you should be fine.
      singulars
    3. COHa! Sorry, siebz0r, but your argument has failed to sway me from my path :) The schemas here are part of a larger set of schema&wsdl, like most of the web services we implement. In my experience, it has proven far more interoperable and powerful to ensure that the control files are top notch...starting with bulletproof schema&wsdl enables others to implement clients to our services using any backing impl they choose (so long as their client speaks our schema fluently). Meanwhile, we get to generate the backbone of our service and write a very little glue code and we're on our way. Besides...
      singulars
 

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