Rev 312 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="UTF-8"?><document xmlns="http://maven.apache.org/XDOC/2.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"><body><section name="Hibernate Spatial 4.x"><subsection name="Installing Hibernate Spatial"><p>You will need to have the following libraries in your classpath:hibernate, a JDBC driver and hibernate-spatial.jar, plus all transitive dependencies.</p><p>Geographic objects (or features) are characterized by having a geometry attribute: an attribute thatdescribes thelocation and geometry of the object by means of a set of coordinates. Hibernate Spatialuses the Geometry package of the<a href="http://tsusiatsoftware.net/jts/main.html">Java Topology Suite</a>to represent the geometries in Java.</p></subsection><subsection name="Configuring a spatial dialect"><p>If you want to use the geographic data support, you will need to configure Hibernatewith the appropriate Spatial Dialect. For example, to use the postgis spatial data supportin Postgresql, you need to add the following line in your hibernate.cfg.xml.</p><source>...<property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>...</source><p>The property value is here the class name of the dialect that extends the Hibernate Postgresql dialectto include supportfor spatial data.</p></subsection><subsection name="Mapping Geometries"><p>Geographic objects can now be represented in Java by means of POJO's that have a Geometry-valuedproperty.Since we use the Java Topology Suite to represent geometries, this looks like:</p><source>import com.vividsolutions.jts.geom.Geometry;...public Class SomeGeographicClass {...private Geometry geometry;...public Geometry getGeometry(){return this.geom;}public void setGeometry(Geometry geometry){this.geometry = geometry;}...}</source><p>The geometry property can be mapped by Hibernate by means of the special typeorg.hibernatespatial.GeometryUserType, like this</p><source>...<property name="geometry" type="org.hibernate.spatial.GeometryType"><column name="geom" /></property>...</source><p>Working with geographic data (geometry-valued properties) is now exactly the same as working with anyother Hibernate-supported type.</p></subsection></section><section name="Hibernate Spatial 1.x"><subsection name="Installing Hibernate Spatial"><p>You will need to have the following libraries in your classpath:hibernate (plus its dependencies), a JDBC driver for you database,hibernate-spatial.jar and the appropriate spatial dialect provider for your database, and finallythe <a href="http://tsusiatsoftware.net/jts/main.html">Java Topology Suite</a> (jts.jar).Depending on the database that you use, you might also need some helper libraries forthat provide geographic data support for the JDBC driver. Consult the dialect providerdocumentation for more information about this.</p><p>Hibernate-spatial.jar provides the generic extension mechanism for workingwith geographic data; the dialect providers contribute the database-specificparts.</p><p>Geographic objects (or features) are characterized by having a geometry attribute: an attribute thatdescribes thelocation and geometry of the object by means of a set of coordinates. Hibernate Spatialuses the Geometry package of the<a href="http://tsusiatsoftware.net/jts/main.html">Java Topology Suite</a>to represent the geometries in Java.</p></subsection><subsection name="Configuring a spatial dialect"><p>If you want to use the geographic data support, you will need to configure Hibernatewith the appropriate Spatial Dialect. For example, to use the postgis spatial data supportin Postgresql, you need to add the following line in your hibernate.cfg.xml.</p><source>...<property name="hibernate.dialect">org.hibernatespatial.postgis.PostgisDialect</property>...</source><p>The property value is here the class name of the dialect that extends the Hibernate Postgresql dialectto include supportfor spatial data.</p></subsection><subsection name="Mapping Geometries"><p>Geographic objects can now be represented in Java by means of POJO's that have a Geometry-valuedproperty.Since we use the Java Topology Suite to represent geometries, this looks like:</p><source>import com.vividsolutions.jts.geom.Geometry;...public Class SomeGeographicClass {...private Geometry geometry;...public Geometry getGeometry(){return this.geom;}public void setGeometry(Geometry geometry){this.geometry = geometry;}...}</source><p>The geometry property can be mapped by Hibernate by means of the special typeorg.hibernatespatial.GeometryUserType, like this</p><source>...<property name="geometry" type="org.hibernatespatial.GeometryUserType"><column name="geom" /></property>...</source><p>Working with geographic data (geometry-valued properties) is now exactly the same as working with anyother Hibernate-supported type.</p></subsection></section></body></document>