Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Geomajas Hibernate layer plugin</title><link rel="stylesheet" href="css/geomajas.css" type="text/css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.75.2"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book" title="Geomajas Hibernate layer plugin"><div class="titlepage"><div><div><h1 class="title"><a name="book"></a>Geomajas Hibernate layer plugin</h1></div><div><div class="authorgroup">
			<h3 class="corpauthor">Geomajas Developers and Geosparc</h3>
		</div></div><div><p class="releaseinfo">1.14.0</p></div><div><p class="copyright">Copyright &copy; 2010-2014 Geosparc nv</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#chapter-introduction">1. Introduction</a></span></dt><dt><span class="chapter"><a href="#chapter-configuration">2. Configuration</a></span></dt><dd><dl><dt><span class="section"><a href="#dependencies">1. Dependencies</a></span></dt><dt><span class="section"><a href="#basichib">2. Basic Hibernate configuration</a></span></dt><dt><span class="section"><a href="#springtx">3. Spring transaction configuration</a></span></dt><dt><span class="section"><a href="#confvl">4. Configuring a vector layer</a></span></dt><dd><dl><dt><span class="section"><a href="#spatialtable">4.1. Spatial database table</a></span></dt><dt><span class="section"><a href="#ormap">4.2. Java O/R mapping</a></span></dt><dt><span class="section"><a href="#vlconf">4.3. Vector layer configuration</a></span></dt></dl></dd></dl></dd><dt><span class="chapter"><a href="#chapter-howto">3. How-to</a></span></dt><dd><dl><dt><span class="section"><a href="#d4e174">1. How to use a many-to-one relation</a></span></dt><dd><dl><dt><span class="section"><a href="#d4e184">1.1. Spatial database tables</a></span></dt><dt><span class="section"><a href="#d4e194">1.2. Java O/R mapping</a></span></dt><dt><span class="section"><a href="#d4e205">1.3. Vector layer configuration</a></span></dt></dl></dd><dt><span class="section"><a href="#d4e212">2. How to use a one-to-many relation</a></span></dt><dt><span class="section"><a href="#d4e215">3. How to create my own DAOs</a></span></dt><dt><span class="section"><a href="#d4e227">4. How to use scrollable resultsets</a></span></dt><dt><span class="section"><a href="#d4e237">5. How to configure a connection pool</a></span></dt><dt><span class="section"><a href="#d4e244">6. How to use a second level cache</a></span></dt><dt><span class="section"><a href="#d4e251">7. Error "Operation on two geometries with different SRIDs"</a></span></dt></dl></dd></dl></div><div class="list-of-examples"><p><b>List of Examples</b></p><dl><dt>2.1. <a href="#HibernateLayerDependency">Hibernate layer dependency</a></dt><dt>2.2. <a href="#d4e38">Hibernate layer dependency with using geomajas-project-server in dependency management</a></dt><dt>2.3. <a href="#d4e43">Hibernate 3.6 - Hibernate spatial 1.1 dependencies</a></dt><dt>2.4. <a href="#d4e53">Example hibernate.cfg.xml</a></dt><dt>2.5. <a href="#HibernateTx">Hibernate transaction configuration</a></dt><dt>2.6. <a href="#d4e94">SQL for creating a PostGIS spatial table</a></dt><dt>2.7. <a href="#d4e101">AreaOfInterest class</a></dt><dt>2.8. <a href="#d4e123">VectorLayerInfo for the AreaOfInterest class</a></dt><dt>2.9. <a href="#d4e142">Hibernate layer definition</a></dt><dt>3.1. <a href="#d4e187">SQL for creating a PostGIS spatial table</a></dt><dt>3.2. <a href="#d4e191">SQL for creating a PostGIS spatial table</a></dt><dt>3.3. <a href="#d4e197">AoiType class</a></dt><dt>3.4. <a href="#d4e201">AreaOfInterest class</a></dt><dt>3.5. <a href="#d4e208">VectorLayerInfo for the AreaOfInterest class</a></dt><dt>3.6. <a href="#d4e219">DAO interface</a></dt><dt>3.7. <a href="#d4e223">DAO implementation</a></dt><dt>3.8. <a href="#d4e232">Hibernate layer definition</a></dt></dl></div>
	

	

	

	<div class="chapter" title="Chapter&nbsp;1.&nbsp;Introduction"><div class="titlepage"><div><div><h2 class="title"><a name="chapter-introduction"></a>Chapter&nbsp;1.&nbsp;Introduction</h2></div></div></div>
  

  <p>This plug-in represents a vector layer implementation based upon the
  popular Hibernate O/R mapping framework. It uses a special spatial extension
  of Hibernate, unsurprisingly called Hibernate Spatial. The Hibernate Spatial
  project has its project website at <a class="ulink" href="http://www.hibernatespatial.org/" target="_top">http://www.hibernatespatial.org</a>.
  The spatial extensions or dialects (in Hibernate language), that Hibernate
  Spatial adds, allow the definition of spatial types and the execution of
  spatial queries in a database independent way.</p>

  <p>At this moment, the Hibernate layer plug-in supports the following
  databases:</p>

  <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
      <p>Oracle SDO; It has been tested with Oracle 10i, but it should work
      equally well with Oracle 9i and Oracle 11g.</p>
    </li><li class="listitem">
      <p>Postgresql/PostGIS: PostGIS 1.1.6 and higher.</p>
    </li><li class="listitem">
      <p>Mircosoft SQL server 2008. Currently only the Geometry types are
      supported.</p>
    </li><li class="listitem">
      <p>MySQL: Works with MySQL 5.0 and higher. Note that MySQL does not
      completely implement the OGC Simple Feature Specification. Some
      functions that work for PostGIS or Oracle may fail to work for
      MySQL.</p>
    </li></ul></div>

  <p>The real strength of this plug-in lies in the fact that it allows you
  to deal with geographic data in a standardized way. It abstracts away from
  the specific way your database supports geographic data, and provides a
  standardized, cross-database interface to geographic data storage and query
  functions.</p>
</div>

	<div class="chapter" title="Chapter&nbsp;2.&nbsp;Configuration"><div class="titlepage"><div><div><h2 class="title"><a name="chapter-configuration"></a>Chapter&nbsp;2.&nbsp;Configuration</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#dependencies">1. Dependencies</a></span></dt><dt><span class="section"><a href="#basichib">2. Basic Hibernate configuration</a></span></dt><dt><span class="section"><a href="#springtx">3. Spring transaction configuration</a></span></dt><dt><span class="section"><a href="#confvl">4. Configuring a vector layer</a></span></dt><dd><dl><dt><span class="section"><a href="#spatialtable">4.1. Spatial database table</a></span></dt><dt><span class="section"><a href="#ormap">4.2. Java O/R mapping</a></span></dt><dt><span class="section"><a href="#vlconf">4.3. Vector layer configuration</a></span></dt></dl></dd></dl></div>
  

  <p></p>

  <div class="section" title="1.&nbsp;Dependencies"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="dependencies"></a>1.&nbsp;Dependencies</h2></div></div></div>
    

    <p>In order to work with the Hibernate layer plug-in, you need multiple
    libraries to be present on your classpath: the Geomajas Hibernate plug-in,
    Hibernate Spatial, and drivers for the specific database that you want to
    use.</p>

    <p>Lets say, for example, you want to make use of this plug-in through
    a PostGIS database. Then you would need to include the following
    dependencies:</p>

    <div class="example"><a name="HibernateLayerDependency"></a><p class="title"><b>Example&nbsp;2.1.&nbsp;Hibernate layer dependency</b></p><div class="example-contents">
      

      <pre class="programlisting">&lt;dependency&gt;
    &lt;groupId&gt;org.geomajas.plugin&lt;/groupId&gt;
    &lt;artifactId&gt;geomajas-layer-hibernate&lt;/artifactId&gt;
	 &lt;version&gt;1.14.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.hibernatespatial&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-spatial-postgis&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.postgis&lt;/groupId&gt;
    &lt;artifactId&gt;postgis-jdbc&lt;/artifactId&gt;
    &lt;version&gt;1.1.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;postgresql&lt;/groupId&gt;
    &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
    &lt;version&gt;8.1-407.jdbc3&lt;/version&gt;
&lt;/dependency&gt;</pre>
    </div></div><br class="example-break">

    <p>If you use the geomajas-project-server in your dependencyManagement
    section, then the versions do not need to be included;</p>

    <div class="example"><a name="d4e38"></a><p class="title"><b>Example&nbsp;2.2.&nbsp;Hibernate layer dependency with using geomajas-project-server in dependency management</b></p><div class="example-contents">
      

      <pre class="programlisting">&lt;dependencyManagement&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.geomajas.project&lt;/groupId&gt;
            &lt;artifactId&gt;geomajas-project-server&lt;/artifactId&gt;
		  &lt;version&gt;1.14.0&lt;/version&gt;
            &lt;type&gt;pom&lt;/type&gt;
            &lt;scope&gt;import&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.geomajas.plugin&lt;/groupId&gt;
        &lt;artifactId&gt;geomajas-layer-hibernate&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.hibernatespatial&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-spatial-postgis&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.postgis&lt;/groupId&gt;
        &lt;artifactId&gt;postgis-jdbc&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;postgresql&lt;/groupId&gt;
        &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;</pre>
    </div></div><br class="example-break">

    <p>The Geomajas Hibernate Layer uses Hibernate 3.5.2 and Hibernate
    Spatial 1.0 versions. If you want to work with later versions of Hibernate
    or Hibernate Spatial, you need to adapt the aforementioned dependencies.
    Hibernate Spatial is<a class="ulink" href="???" target="_top"> version dependent </a>on
    Hibernate.</p>

    <div class="example"><a name="d4e43"></a><p class="title"><b>Example&nbsp;2.3.&nbsp;Hibernate 3.6 - Hibernate spatial 1.1 dependencies</b></p><div class="example-contents">
      

      <pre class="programlisting">&lt;dependency&gt;
  &lt;groupId&gt;org.geomajas.plugin&lt;/groupId&gt;
  &lt;artifactId&gt;geomajas-layer-hibernate&lt;/artifactId&gt;
  &lt;exclusions&gt;
    &lt;!--add exclusion for hibernate-annotations in geomajas-layer-hibernate, as it will add the wrong version of annotations.--&gt;
    &lt;exclusion&gt;
       &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
       &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
    &lt;/exclusion&gt;
  &lt;/exclusions&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
    &lt;version&gt;3.6.10.Final&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
     &lt;groupId&gt;org.hibernatespatial&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-spatial&lt;/artifactId&gt;
     &lt;version&gt;1.1.1&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
     &lt;groupId&gt;org.hibernatespatial&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-spatial-postgis&lt;/artifactId&gt;
     &lt;version&gt;1.1.1&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
     &lt;groupId&gt;postgresql&lt;/groupId&gt;
     &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
     &lt;version&gt;9.1-901.jdbc4&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
     &lt;groupId&gt;org.postgis&lt;/groupId&gt;
     &lt;artifactId&gt;postgis-jdbc&lt;/artifactId&gt;
     &lt;version&gt;1.3.3&lt;/version&gt;
     &lt;exclusions&gt;
         &lt;exclusion&gt;
             &lt;groupId&gt;org.postgis&lt;/groupId&gt;
             &lt;artifactId&gt;postgis-stubs&lt;/artifactId&gt;
         &lt;/exclusion&gt;
     &lt;/exclusions&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;com.jolbox&lt;/groupId&gt;
    &lt;artifactId&gt;bonecp&lt;/artifactId&gt;
    &lt;version&gt;0.7.1-rc3&lt;/version&gt;
&lt;/dependency&gt;</pre>
    </div></div><br class="example-break">
  </div>

  <div class="section" title="2.&nbsp;Basic Hibernate configuration"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="basichib"></a>2.&nbsp;Basic Hibernate configuration</h2></div></div></div>
    

    <p>First of all, you need to configure the basic Hibernate library. On
    the root of your classpath (for a Maven project this is typically
    <code class="code">src/main/resources/</code>), you need a
    <code class="code">hibernate.cfg.xml</code> file. This configuration file determines
    the dialect to use (PostGIS in the example below), and also which Java
    classes that will provide the mapping onto the database. In the example
    below, there is one Java class
    (<code class="code">org.geomajas.server.pojo.MyPojoClass</code>):</p>

    <div class="example"><a name="d4e53"></a><p class="title"><b>Example&nbsp;2.4.&nbsp;Example hibernate.cfg.xml</b></p><div class="example-contents">
      

      <pre class="programlisting">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
&lt;hibernate-configuration&gt;
   &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernatespatial.postgis.PostgisDialect&lt;/property&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.HashtableCacheProvider&lt;/property&gt;
      &lt;property name="show_sql"&gt;false&lt;/property&gt;

      &lt;mapping class="org.geomajas.server.pojo.MyPojoClass" /&gt;
      .....

   &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;</pre>
    </div></div><br class="example-break">

    <p>It is recommended to read up on the Hibernate configuration options
    on the <a class="ulink" href="http://www.hibernate.org/" target="_top">official Hibernate
    website</a>, to get a better grasp of all the possibilities Hibernate
    provides.</p>

    <div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
      <p>In normal Hibernate applications, you would also configure you
      database connection parameters in the hibernate.cfg.xml. Geomajas
      however uses the Spring framework, and so provides the option of
      injecting Session factories at run-time. This can be a very powerfull
      approach, as it allows you to set up new DAO's etc. much quicker.</p>
    </div>

    <p>So instead of configuring all connection, session and transaction
    parameters through the default Hibernate configuration, it is recommended
    to configure these through Spring.</p>
  </div>

  <div class="section" title="3.&nbsp;Spring transaction configuration"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="springtx"></a>3.&nbsp;Spring transaction configuration</h2></div></div></div>
    

    <p>The Spring framework provides a connection to Hibernate by means of
    the
    <code class="code">org.springframework.orm.hibernate3.HibernateTransactionManager</code>.
    This allows you to make full use of the power of dependency injection in
    your DAOs. In order to get up-and-running, the following parameters need
    to be defined (somewhere in the Spring XML files):</p>

    <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
        <p>The data source: this specifies the connection pool type and the
        connection properties of the database (PostGis in this case).</p>
      </li><li class="listitem">
        <p>The session factory: this is Hibernate's primary singleton and
        used by the Hibernate layer to access the session/connection. It also
        points to the Hibernate configuration file.</p>
      </li><li class="listitem">
        <p>A tag to enable annotation-based transactional behavior,
        internally used by Geomajas to decide which commands need transaction
        support</p>
      </li><li class="listitem">
        <p>The platform transaction manager for Hibernate</p>
      </li></ul></div>

    <p>Here is an example wherein the above parameters are
    configured:</p>

    <div class="example"><a name="HibernateTx"></a><p class="title"><b>Example&nbsp;2.5.&nbsp;Hibernate transaction configuration</b></p><div class="example-contents">

<pre class="programlisting">    &lt;bean id="testDataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
        &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver" /&gt;
        &lt;property name="url" value="jdbc:hsqldb:mem:baseball" /&gt;
        &lt;property name="username" value="sa" /&gt;
        &lt;property name="password" value="" /&gt;
    &lt;/bean&gt;

    &lt;bean id="testSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
        &lt;property name="dataSource" ref="testDataSource" /&gt;
        &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
        &lt;property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /&gt;
    &lt;/bean&gt;

    &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

    &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
        &lt;property name="sessionFactory" ref="testSessionFactory" /&gt;
    &lt;/bean&gt;

    &lt;bean name="simpleDateFormat" class="java.text.SimpleDateFormat"&gt;
        &lt;constructor-arg type="java.lang.String" value="dd/MM/yyyy" /&gt;
    &lt;/bean&gt;
</pre>
</div></div><br class="example-break">
  </div>

  <div class="section" title="4.&nbsp;Configuring a vector layer"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="confvl"></a>4.&nbsp;Configuring a vector layer</h2></div></div></div>
    

    <p>Creating a vector layers with the Geomajas Hibernate plug-in takes a
    bit more work than using the GeoTools layers, but in return it provides
    you with a lot more options. In short, the following actions need to be
    taken in order to set up a vector layer:</p>

    <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
        <p>You need a spatial database with one or more tables. At least
        one table must have a geometric column. This of course falls out of
        the scope of this document, but in order to correctly configure your
        Java pojo objects, it is necessary for you to know what your database
        looks like.</p>
      </li><li class="listitem">
        <p>Configure your Java pojo objects that provide the mapping onto
        the database. Note that these Java classes must be mentioned in the
        hibernate.cfg.cml configuration file.</p>
      </li><li class="listitem">
        <p>Configure a Geomajas vector layer that makes use of the Java
        pojo object.</p>
      </li></ul></div>

    <p>In the following section, an example vector layer will be
    configured. This example will demonstrate a simple case, with a one-to-one
    mapping between a Java class and a single spatial database table.</p>

    <div class="section" title="4.1.&nbsp;Spatial database table"><div class="titlepage"><div><div><h3 class="title"><a name="spatialtable"></a>4.1.&nbsp;Spatial database table</h3></div></div></div>
      

      <p>We start out by creating a simple spatial table in the database
      containing "areas of interest". If you have your own data, you will be
      creating your own database tables.</p>

      <p>In the SQL query below, we create a table with the name
      "areaofinterest" and give it 4 columns: an ID, 2 text columns (title and
      description) and a geometry column (type Polygon).</p>

      <div class="example"><a name="d4e94"></a><p class="title"><b>Example&nbsp;2.6.&nbsp;SQL for creating a PostGIS spatial table</b></p><div class="example-contents">
        

        <pre class="programlisting">CREATE TABLE areaofinterest (
    id integer NOT NULL,
    title character varying(100) NOT NULL,
    description character varying,
    geom geometry,
    CONSTRAINT enforce_dims_geom CHECK ((ndims(geom) = 2)),
    CONSTRAINT enforce_geotype_geom CHECK (((geometrytype(geom) = 'POLYGON'::text) OR (geom IS NULL))),
    CONSTRAINT enforce_srid_geom CHECK ((srid(geom) = 900913))
);</pre>
      </div></div><br class="example-break">
    </div>

    <div class="section" title="4.2.&nbsp;Java O/R mapping"><div class="titlepage"><div><div><h3 class="title"><a name="ormap"></a>4.2.&nbsp;Java O/R mapping</h3></div></div></div>
      

      <p>Assuming that you have a database with spatial data, let us now
      create a Java class that maps onto that database. We will continue using
      the "areaofinterest" database table from the previous section. A java
      class <code class="code">org.geomajas.server.pojo.AreaOfInterest</code> would now
      look like this:</p>

      <div class="example"><a name="d4e101"></a><p class="title"><b>Example&nbsp;2.7.&nbsp;AreaOfInterest class</b></p><div class="example-contents">
        

        <pre class="programlisting">@Entity
@Table(name = "areaofinterest")
public class AreaOfInterest {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, name = "title")
    private String title;

    @Column(name = "description")
    private String description;

    @Type(type = "org.hibernatespatial.GeometryUserType")
    @Column(nullable = false, name = "geom")
    private Geometry geometry;

    // Constructors, getters, and setters
    ....</pre>
      </div></div><br class="example-break">

      <p>At the top of the class, you make a reference to the actual
      database table; in this case "areaofinterest". In the actual Java field
      declarations, you refer to the database columns within the
      "areaofinterest" table.</p>

      <div class="caution" title="Caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3>
          <p>The mappings in your Java class are case sensitive! Typically
          PostGIS will use lowercase characters while Oracle uses uppercase
          characters.</p>

          <p>Also make sure you add the Java class names to the
          hibernate.cfg.cml configuration file.</p>
        </div>

      <div class="tip" title="Tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Tip</h3>
        <p>At this point you might want to check if the O/R mapping is
        correct by writing a DAO and few unit tests.</p>
      </div>

      <p>The Hibernate layer uses the same way to access you class as
      Hibernate itself. If your Hibernate annotations are on the fields (which
      is recommended), then the fields will be used for reading and writing of
      values. If the annotations are on the getters, then the getters and
      setters will be used for reading and writing of values. You can changes
      this at both class and field level by using an AccessType annotation.
      Use <code class="code">@AccessType("property")</code> to use the getters and setters
      and <code class="code">@AccessType("field")</code> to directly access the field
      itself.</p>
    </div>

    <div class="section" title="4.3.&nbsp;Vector layer configuration"><div class="titlepage"><div><div><h3 class="title"><a name="vlconf"></a>4.3.&nbsp;Vector layer configuration</h3></div></div></div>
      

      <p>Now that you have a spatial database table and a Java class to map
      it, it's time to create the actual Geomajas vector layer configuration.
      Following the Geomajas configuration rules, we first configure a
      <code class="code">org.geomajas.configuration.VectorLayerInfo</code> object, and only
      than the actual layer definition.</p>

      <div class="section" title="4.3.1.&nbsp;Configuring the VectorLayerInfo"><div class="titlepage"><div><div><h4 class="title"><a name="vlinfo"></a>4.3.1.&nbsp;Configuring the VectorLayerInfo</h4></div></div></div>
        

        <p>The configuration of the VectorLayerInfo is almost identical as
        with other vector layer plug-ins. The main difference is that the
        dataSourceName in the FeatureInfo needs the Java classname of the
        mapping class (i.e.
        <code class="code">org.geomajas.server.pojo.AreaOfInterest</code>), and the names
        of the attributes, need to point to the fields in that Java
        class.</p>

        <p>So for the Java class from the previous section, we would
        get:</p>

        <div class="example"><a name="d4e123"></a><p class="title"><b>Example&nbsp;2.8.&nbsp;VectorLayerInfo for the AreaOfInterest class</b></p><div class="example-contents">
          

          <pre class="programlisting">&lt;!-- Area Of Interest Vector layer definition --&gt;
&lt;bean name="aoiInfo" class="org.geomajas.configuration.VectorLayerInfo"&gt;
    &lt;property name="layerType" value="POLYGON" /&gt;
    &lt;property name="crs" value="EPSG:900913" /&gt;
    &lt;property name="maxExtent"&gt;
        &lt;bean class="org.geomajas.geometry.Bbox"&gt;
            &lt;property name="x" value="-20026376.393709917" /&gt;
            &lt;property name="y" value="-20026376.393709917" /&gt;
            &lt;property name="width" value="40052752.787419834" /&gt;
            &lt;property name="height" value="40052752.787419834" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="featureInfo" ref="aoiFeatureInfo" /&gt;
    &lt;property name="namedStyleInfos"&gt;
        &lt;list&gt;
            &lt;ref bean="aoiStyleInfo" /&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;!-- Feature (attributes..) definition --&gt;
&lt;bean name="aoiFeatureInfo" class="org.geomajas.configuration.FeatureInfo"&gt;
    &lt;property name="dataSourceName" value="org.geomajas.server.pojo.AreaOfInterest" /&gt;
    &lt;property name="identifier"&gt;
        &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
            &lt;property name="label" value="Id" /&gt;
            &lt;property name="name" value="id" /&gt;
            &lt;property name="type" value="LONG" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="geometryType"&gt;
        &lt;bean class="org.geomajas.configuration.GeometryAttributeInfo"&gt;
            &lt;property name="name" value="geometry" /&gt;
            &lt;property name="editable" value="false" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="attributes"&gt;
        &lt;list&gt;
            &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                &lt;property name="label" value="Title" /&gt;
                &lt;property name="name" value="title" /&gt;
                &lt;property name="editable" value="true" /&gt;
                &lt;property name="identifying" value="true" /&gt;
                &lt;property name="type" value="STRING" /&gt;
            &lt;/bean&gt;
            &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                &lt;property name="label" value="Description" /&gt;
                &lt;property name="name" value="description" /&gt;
                &lt;property name="editable" value="true" /&gt;
                &lt;property name="identifying" value="false" /&gt;
                &lt;property name="type" value="STRING" /&gt;
            &lt;/bean&gt;
        &lt;/list&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;!-- Style definition --&gt;
&lt;bean class="org.geomajas.configuration.NamedStyleInfo" name="aoiStyleInfo"&gt;
    ............Not important here.......
&lt;/bean&gt;</pre>
        </div></div><br class="example-break">

        <p>Make sure to keep an eye on the following:</p>

        <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
            <p>The CRS must be the same as defined in the database
            table.</p>
          </li><li class="listitem">
            <p>The geometry type must be the same as defined in the
            database table.</p>
          </li><li class="listitem">
            <p>The dataSourceName must point to the Java class name.</p>
          </li><li class="listitem">
            <p>All attribute names must point to the fields in the Java
            class.</p>
          </li><li class="listitem">
            <p>Don't just copy/paste; there is no styling information in
            the example above ;-)</p>
          </li></ul></div>
      </div>

      <div class="section" title="4.3.2.&nbsp;Configuring the layer"><div class="titlepage"><div><div><h4 class="title"><a name="conflayer"></a>4.3.2.&nbsp;Configuring the layer</h4></div></div></div>
        

        <p>When the <code class="code">org.geomajas.configuration.VectorLayerInfo</code>
        definition has been defined, it is time to define the actual layer.
        This layer must of course point to the VectorLayerInfo object that we
        just defined, but it must also make use of the SessionFactory that was
        configured:</p>

        <div class="example"><a name="d4e142"></a><p class="title"><b>Example&nbsp;2.9.&nbsp;Hibernate layer definition</b></p><div class="example-contents">
          

          <pre class="programlisting">&lt;!-- Needed when the Hibernate pojo classes contain dates. --&gt;
&lt;bean name="simpleDateFormat" class="java.text.SimpleDateFormat"&gt;
    &lt;constructor-arg type="java.lang.String" value="dd/MM/yyyy" /&gt;
&lt;/bean&gt;

&lt;bean name="aoi" class="org.geomajas.layer.hibernate.HibernateLayer"&gt;
    &lt;property name="layerInfo" ref="aoiInfo" /&gt; &lt;!-- see previous section --&gt;
    &lt;property name="sessionFactory" ref="simpleSessionFactory" /&gt;

    &lt;!-- Needed when the Hibernate pojo classes contain dates. --&gt;
    &lt;property name="dateFormat" ref="simpleDateFormat" /&gt;
&lt;/bean&gt;</pre>
        </div></div><br class="example-break">

        <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
          <p>This configuration only works for 1.9.0 and higher. Earlier
          versions also had to define the featureModel property as in this
          example (shown without the date format
          configuration).</p><pre class="programlisting">&lt;bean name="aoi" class="org.geomajas.layer.hibernate.HibernateLayer"&gt;
    &lt;property name="layerInfo" ref="aoiInfo" /&gt;
    &lt;property name="featureModel"&gt;
        &lt;bean class="org.geomajas.layer.hibernate.HibernateFeatureModel"&gt;
            &lt;property name="sessionFactory" ref="simpleSessionFactory" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="sessionFactory" ref="simpleSessionFactory" /&gt;
&lt;/bean&gt;</pre>
        </div>

        <p>Note that in the example above, some extra configuration was
        added to support the use of java.util.Date objects as fields within
        Java pojo classes. In the case of the AreaOfInterest layer there was
        no such date, so technically this addition was not necessary.</p>

        <p>The properties which may be defined on a HibernateLayer object
        are:</p>

        <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
            <p><span class="emphasis"><em>layerInfo</em></span>: the description of the
            features.</p>
          </li><li class="listitem">
            <p><span class="emphasis"><em>featureModel</em></span>: the feature model to use
            for this layer.</p>
          </li><li class="listitem">
            <p><span class="emphasis"><em>sessionfactory</em></span>: the session factory to
            use for this layer.</p>
          </li><li class="listitem">
            <p><span class="emphasis"><em>scrollableResultSet</em></span>: indicates whether
            a scrollable resultset needs to be used. This can be more
            efficient when queries return many records but needs to be
            supported by your database driver.</p>
          </li><li class="listitem">
            <p><span class="emphasis"><em>useLazyFeatureConversion</em></span>: indicates
            whether lazy feature conversion should be used. This is set to
            true by default. You should only set this to false if none of
            attributes in the feature are lazy loaded.</p>
          </li></ul></div>

        <div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
          <p>You have now successfully created a Geomajas VectorLayer
          definition, using the Hibernate layer plug-in. All you have to do
          now, is use it in your map configuration.</p>
        </div>

        <div class="important" title="Important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Important</h3>
          <p>This tutorial only covered the most basic case of mapping a
          single table onto a Java class. More complex mappings (many-to-one
          and one-to-many) are also supported. See the section <a class="xref" href="#chapter-howto" title="Chapter&nbsp;3.&nbsp;How-to">Chapter&nbsp;3, <i>How-to</i></a> for more information.</p>
        </div>
      </div>
    </div>
  </div>
</div>

	<div class="chapter" title="Chapter&nbsp;3.&nbsp;How-to"><div class="titlepage"><div><div><h2 class="title"><a name="chapter-howto"></a>Chapter&nbsp;3.&nbsp;How-to</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="#d4e174">1. How to use a many-to-one relation</a></span></dt><dd><dl><dt><span class="section"><a href="#d4e184">1.1. Spatial database tables</a></span></dt><dt><span class="section"><a href="#d4e194">1.2. Java O/R mapping</a></span></dt><dt><span class="section"><a href="#d4e205">1.3. Vector layer configuration</a></span></dt></dl></dd><dt><span class="section"><a href="#d4e212">2. How to use a one-to-many relation</a></span></dt><dt><span class="section"><a href="#d4e215">3. How to create my own DAOs</a></span></dt><dt><span class="section"><a href="#d4e227">4. How to use scrollable resultsets</a></span></dt><dt><span class="section"><a href="#d4e237">5. How to configure a connection pool</a></span></dt><dt><span class="section"><a href="#d4e244">6. How to use a second level cache</a></span></dt><dt><span class="section"><a href="#d4e251">7. Error "Operation on two geometries with different SRIDs"</a></span></dt></dl></div>
  

  <p>This section covers a few specific cases that might come in handy when
  really using the Geomajas Hibernate layer plug-in.</p>

  <div class="section" title="1.&nbsp;How to use a many-to-one relation"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e174"></a>1.&nbsp;How to use a many-to-one relation</h2></div></div></div>
    

    <p>A many-to-one relation is the Hibernate term for what would in the
    database world be called a foreign key. Say you have a table
    ("areaofinterest") with a foreign key to some other table("aoitype"). In
    order to get this relation configured as an attribute within the Geomajas
    layer definition, the following must be done:</p>

    <div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
        <p>Both tables must actually exist in the database.</p>
      </li><li class="listitem">
        <p>For both tables a Java O/R mapping class must be defined.</p>
      </li><li class="listitem">
        <p>The Geomajas layer definition must include the many-to-one
        relation in it's attribute definitions.</p>
      </li></ul></div>

    <div class="section" title="1.1.&nbsp;Spatial database tables"><div class="titlepage"><div><div><h3 class="title"><a name="d4e184"></a>1.1.&nbsp;Spatial database tables</h3></div></div></div>
      

      <p>This time, 2 tables must be present in the database, in order for
      one to be able to point to the other. Let's say the second table,
      containing the type, is very simple and holds only an ID and a
      description:</p>

      <div class="example"><a name="d4e187"></a><p class="title"><b>Example&nbsp;3.1.&nbsp;SQL for creating a PostGIS spatial table</b></p><div class="example-contents">
        

        <pre class="programlisting">CREATE TABLE aoitype (
    id integer NOT NULL,
    description character varying,
);</pre>
      </div></div><br class="example-break">

      <p>Now we have the "areaofinterest" table point to it with a foreign
      key ("type_id"):</p>

      <div class="example"><a name="d4e191"></a><p class="title"><b>Example&nbsp;3.2.&nbsp;SQL for creating a PostGIS spatial table</b></p><div class="example-contents">
        

        <pre class="programlisting">CREATE TABLE areaofinterest (
    id integer NOT NULL,
    title character varying(100) NOT NULL,
    description character varying,
    type_id integer NOT NULL,
    geom geometry,
    CONSTRAINT enforce_dims_geom CHECK ((ndims(geom) = 2)),
    CONSTRAINT enforce_geotype_geom CHECK (((geometrytype(geom) = 'POLYGON'::text) OR (geom IS NULL))),
    CONSTRAINT enforce_srid_geom CHECK ((srid(geom) = 900913))
);

ALTER TABLE ONLY areaofinterest ADD CONSTRAINT fk_areaofinterest_aoitype FOREIGN KEY (type_id) REFERENCES aoitype(id);</pre>
      </div></div><br class="example-break">
    </div>

    <div class="section" title="1.2.&nbsp;Java O/R mapping"><div class="titlepage"><div><div><h3 class="title"><a name="d4e194"></a>1.2.&nbsp;Java O/R mapping</h3></div></div></div>
      

      <p>For both database table, we will now create Java mapping classes.
      First the "aoitype":</p>

      <div class="example"><a name="d4e197"></a><p class="title"><b>Example&nbsp;3.3.&nbsp;AoiType class</b></p><div class="example-contents">
        

        <pre class="programlisting">@Entity
@Table(name = "aoitype")
public class AoiType{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "description")
    private String description;

    // Constructors, getters, and setters
    ....</pre>
      </div></div><br class="example-break">

      <p>We now update the AreaOfInterest class to include the ManyToOne
      relation:</p>

      <div class="example"><a name="d4e201"></a><p class="title"><b>Example&nbsp;3.4.&nbsp;AreaOfInterest class</b></p><div class="example-contents">
        

        <pre class="programlisting">@Entity
@Table(name = "areaofinterest")
public class AreaOfInterest {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, name = "title")
    private String title;

    @Column(name = "description")
    private String description;

<span class="bold"><strong>    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "type_id", nullable = false)
    private AoiType type;</strong></span>

    @Type(type = "org.hibernatespatial.GeometryUserType")
    @Column(nullable = false, name = "geom")
    private Geometry geometry;

    // Constructors, getters, and setters
    ....</pre>
      </div></div><br class="example-break">
    </div>

    <div class="section" title="1.3.&nbsp;Vector layer configuration"><div class="titlepage"><div><div><h3 class="title"><a name="d4e205"></a>1.3.&nbsp;Vector layer configuration</h3></div></div></div>
      

      <p>Lastly, you add the new many-to-one relation to the list of
      attributes:</p>

      <div class="example"><a name="d4e208"></a><p class="title"><b>Example&nbsp;3.5.&nbsp;VectorLayerInfo for the AreaOfInterest class</b></p><div class="example-contents">
        

        <pre class="programlisting">...
    &lt;property name="attributes"&gt;
        &lt;list&gt;
            &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                &lt;property name="label" value="Title" /&gt;
                &lt;property name="name" value="title" /&gt;
                &lt;property name="editable" value="true" /&gt;
                &lt;property name="identifying" value="true" /&gt;
                &lt;property name="type" value="STRING" /&gt;
            &lt;/bean&gt;
            &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                &lt;property name="label" value="Description" /&gt;
                &lt;property name="name" value="description" /&gt;
                &lt;property name="editable" value="true" /&gt;
                &lt;property name="identifying" value="false" /&gt;
                &lt;property name="type" value="STRING" /&gt;
            &lt;/bean&gt;

<span class="bold"><strong>            &lt;bean class="org.geomajas.configuration.AssociationAttributeInfo"&gt;
                &lt;property name="label" value="Type" /&gt;
                &lt;property name="name" value="type" /&gt;
                &lt;property name="editable" value="true" /&gt;
                &lt;property name="identifying" value="false" /&gt;
                &lt;property name="type" value="MANY_TO_ONE" /&gt;
                &lt;property name="feature"&gt;
                    &lt;bean class="org.geomajas.configuration.FeatureInfo"&gt;
                        &lt;property name="dataSourceName" value="org.geomajas.server.pojo.AoiType" /&gt;
                        &lt;property name="identifier"&gt;
                            &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                                &lt;property name="label" value="Id" /&gt;
                                &lt;property name="name" value="id" /&gt;
                                &lt;property name="type" value="LONG" /&gt;
                            &lt;/bean&gt;
                        &lt;/property&gt;
                        &lt;property name="attributes"&gt;
                            &lt;list&gt;
                                &lt;bean class="org.geomajas.configuration.PrimitiveAttributeInfo"&gt;
                                    &lt;property name="label" value="Description" /&gt;
                                    &lt;property name="name" value="description" /&gt;
                                    &lt;property name="editable" value="false" /&gt;
                                    &lt;property name="identifying" value="true" /&gt;
                                    &lt;property name="type" value="STRING" /&gt;
                                &lt;/bean&gt;
                            &lt;/list&gt;
                        &lt;/property&gt;
                    &lt;/bean&gt;
                &lt;/property&gt;
            &lt;/bean&gt;

</strong></span>        &lt;/list&gt;
    &lt;/property&gt;
...</pre>
      </div></div><br class="example-break">
    </div>
  </div>

  <div class="section" title="2.&nbsp;How to use a one-to-many relation"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e212"></a>2.&nbsp;How to use a one-to-many relation</h2></div></div></div>
    

    <p>TODO</p>
  </div>

  <div class="section" title="3.&nbsp;How to create my own DAOs"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e215"></a>3.&nbsp;How to create my own DAOs</h2></div></div></div>
    

    <p>If you have followed the configuration guidelines and made use of
    the Spring configuration options, this will be a piece of cake: we
    inject the SessionFactory at run-time into your DAO implementation, and
    this SessionFactory will take care of all session and transaction
    handling.</p>

    <p>Say, for example, we have the following DAO interface:</p>

    <div class="example"><a name="d4e219"></a><p class="title"><b>Example&nbsp;3.6.&nbsp;DAO interface</b></p><div class="example-contents">
      

      <pre class="programlisting">public interface ZoneDao {

    List&lt;AreaOfInterest&gt; getByTitle(String title);
}</pre>
    </div></div><br class="example-break">

    <p>In this case, a possible implementation could look like this:</p>

    <div class="example"><a name="d4e223"></a><p class="title"><b>Example&nbsp;3.7.&nbsp;DAO implementation</b></p><div class="example-contents">
      

      <pre class="programlisting">@Component
@Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
public class ZoneDaoImpl implements ZoneDao {

    @Autowired
    private SessionFactory sessionFactory;

    public List&lt;AreaOfInterest&gt; getByTitle(String title) {
        Session session = sessionFactory.getCurrentSession();
        Query query = session.createQuery("FROM AreaOfInterest where title LIKE " + title);
        return (List&lt;AreaOfInterest&gt;) query.list();
    }
}</pre>
    </div></div><br class="example-break">

    <p>And that's it! No more worrying about sessions or transactions, or
    how the hell everything should get initialized...</p>
  </div>

  <div class="section" title="4.&nbsp;How to use scrollable resultsets"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e227"></a>4.&nbsp;How to use scrollable resultsets</h2></div></div></div>
    

    <p>If you have a very large table it might be desirable to retrieve
    features not as a list but as a scrollable resultset so only the features
    you actually use are also retrieved from the underlying database (for
    instance when paging).</p>

    <p>To retrieve features as a scrollable resultset you add the property
    <span class="property">scrollableResultSet to your hibernate layer
    definition:</span></p>

    <div class="example"><a name="d4e232"></a><p class="title"><b>Example&nbsp;3.8.&nbsp;Hibernate layer definition</b></p><div class="example-contents">
      

      <pre class="programlisting">&lt;bean name="midori" class="org.geomajas.layer.hibernate.HibernateLayer"&gt;
    &lt;property name="layerInfo" ref="midoriInfo" /&gt;
<span class="bold"><strong>    &lt;property name="scrollableResultSet" value="true" /&gt;</strong></span>
    &lt;property name="featureModel"&gt;
        &lt;bean class="org.geomajas.layer.hibernate.HibernateFeatureModel"&gt;
            &lt;property name="sessionFactory" ref="simpleSessionFactory" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
    &lt;property name="sessionFactory" ref="simpleSessionFactory" /&gt;
&lt;/bean&gt;</pre>
    </div></div><br class="example-break">

    <p>Please note that your databasedriver needs to support Scrollable
    resultsets.</p>
  </div>

  <div class="section" title="5.&nbsp;How to configure a connection pool"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e237"></a>5.&nbsp;How to configure a connection pool</h2></div></div></div>
    

    <p>There are many connection pool libraries which can be used. Some of
    the best known include DBCP and C3P0. The former may cause deadlocks while
    the latter is not known for its speed. An alternative connection pool
    library is <a class="ulink" href="http://jolbox.com/" target="_top">BoneCP</a>. This can be
    included using the following dependency:</p>

    <pre class="programlisting">&lt;dependency&gt;
    &lt;groupId&gt;com.jolbox&lt;/groupId&gt;
    &lt;artifactId&gt;bonecp&lt;/artifactId&gt;
&lt;/dependency&gt;</pre>

    <p>A sample Hibernate definition looks like this:</p>

    <pre class="programlisting">&lt;!-- BoneCP configuration --&gt;
&lt;bean id="postgisDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close"&gt;
   &lt;property name="driverClass" value="org.postgresql.Driver" /&gt;
   &lt;property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/databaseName" /&gt;
   &lt;property name="username" value="dbUser"/&gt;
   &lt;property name="password" value="dbPw"/&gt;
   &lt;property name="idleConnectionTestPeriod" value="60"/&gt;
   &lt;property name="idleMaxAge" value="240"/&gt;
   &lt;property name="maxConnectionsPerPartition" value="30"/&gt;
   &lt;property name="minConnectionsPerPartition" value="10"/&gt;
   &lt;property name="partitionCount" value="3"/&gt;
   &lt;property name="acquireIncrement" value="5"/&gt;
   &lt;property name="statementsCacheSize" value="100"/&gt;
   &lt;property name="releaseHelperThreads" value="3"/&gt;
&lt;/bean&gt;

&lt;!-- Hibernate SessionFactory --&gt;
&lt;bean id="postgisSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="postgisDataSource" /&gt;
    &lt;property name="configLocation" value="classpath:/hibernate.cfg.xml" /&gt;
    &lt;property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /&gt;
&lt;/bean&gt;

&lt;!-- enable the configuration of transactional behavior based on annotations --&gt;
&lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

&lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
    &lt;property name="sessionFactory" ref="postgisSessionFactory" /&gt;
&lt;/bean&gt;

&lt;!-- Needed when the Hibernate pojo classes contain dates. --&gt;
&lt;bean name="simpleDateFormat" class="java.text.SimpleDateFormat"&gt;
    &lt;constructor-arg type="java.lang.String" value="dd/MM/yyyy" /&gt;
&lt;/bean
</pre>
  </div>

  <div class="section" title="6.&nbsp;How to use a second level cache"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e244"></a>6.&nbsp;How to use a second level cache</h2></div></div></div>
    

    <p>In your hibernate.cfg.xml file, add the following excerpt:</p>

    <pre class="programlisting">&lt;property name="hibernate.cache.use_second_level_cache"&gt;true&lt;/property&gt;
&lt;property name="hibernate.cache.use_query_cache"&gt;true&lt;/property&gt;
&lt;property name="hibernate.cache.region.factory_class"&gt;
    org.hibernate.cache.infinispan.InfinispanRegionFactory
&lt;/property&gt;
</pre>

    <p>To make sure this works, you also need the <a class="ulink" href="http://www.jboss.org/infinispan/" target="_top">Infinispan</a> dependencies
    (these are already available when using the caching plug-in. Additionally,
    you also need the Hibernate-Infinispan bridge:</p>

    <pre class="programlisting">&lt;dependency&gt;
    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-infinispan&lt;/artifactId&gt;
&lt;/dependency&gt;
</pre>
  </div>

  <div class="section" title="7.&nbsp;Error &#34;Operation on two geometries with different SRIDs&#34;"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d4e251"></a>7.&nbsp;Error "Operation on two geometries with different SRIDs"</h2></div></div></div>
    

    <p>This is an exception which can occur of your geometries are stored
    in the database using a different SRID as the one configured in the
    layer.</p>

    <p>You have to make sure that the SRID mathes the declaration.</p>

    <p>When converting a shapefile using shp2pqsql, you have to specify the
    SRID to be set (as this defaults to -1). Use a command like:</p>

    <pre class="programlisting">shp2pgsql -s 4326 shape-base-name</pre>
  </div>
</div>

</div></body></html>
New to GrepCode? Check out our FAQ X