[postgis-users] Experiment: Glassfish/EJB3 and PostGIS

Bastian Voigt post at bastian-voigt.de
Thu May 10 05:40:12 PDT 2007


Hi *,
I would like to share my experiences with PostGIS on the Glassfish 
Application Server with EJB3. In short: It works, but there are some 
problems... please read on for more details:

I was able to use this very simple mapping for entity classes

------------------------------
@Entity
class User
{
    ...
    @Column(name="region")
    private PGgeometry region;

    public Polygon getRegion()
    {
       if(region!=null)
          return (Polygon)region.getGeometry();
    }
}
------------------------------

So far, it works very fine! I was amazed how easy this was...
Now the Setter:

------------------------------
public void setRegion(Polygon p)
{
    region = new PGgeometry(p);
}
------------------------------

Wow, really easy again. Now I'm able to use geo data in the EJB3 world. 
Queries with "intersects", "contains" etc. can be made as native SQL 
queries.

And now the big disappointment:

In my Session Bean I tried to create a User without a region, a NULL 
value should be stored in the database for the polygon:

User u = new User();
u.setFirstname("Test");
u.setLastname("Ohr");
u.setUsername("test0r");
u.setCity("Hamburg");
em.persist(u);

This gives the following exception:
org.postgresql.util.PSQLException:
ERROR: Column "region" is of type geometry, but the expression is of 
type "character varying"
Error Code: 0
Call:INSERT INTO webuser (lastname, region, address, city, username, 
firstname) VALUES (?, ?, ?, ?, ?, ?)
        bind => [Ohr, null, null, Hamburg, test0r, Test]

Can anybody tell where this error comes from?

-- 
Bastian Voigt
Neumünstersche Straße 4
20251 Hamburg
telefon +49 - 40  - 67957171
mobil   +49 - 179 - 4826359





More information about the postgis-users mailing list