Looking for sample using hibernate spatial with JPA

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Looking for sample using hibernate spatial with JPA

Farrukh Najmi

Hello,

Is there an example of using hibernate spatial with Java persistence API
(JPA) anywhere?
Thanks for any clues.

--
Regards,
Farrukh
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Farrukh Najmi
Farrukh Najmi wrote:
> Hello,
>
> Is there an example of using hibernate spatial with Java persistence API
> (JPA) anywhere?
> Thanks for any clues.
>
>  

The following archived thread suggests that JPA hibernate spatial works
with JPA:

<http://www.nabble.com/No-Dialect-mapping-for-JDBC-type:-2003-td15459772.html>

According to it, the annotation on entity class looks like:

@Column(name="LOC",columnDefinition="GEOMETRY")
@Type(type="org.*hibernatespatial*.GeometryUserType")
public Point getLocation(){
    return this.location;
}

But I do not know where the annotation class "Type" is defined. It does
not seem to be part of JPA.
In JPA the closest thing seems to be the columnDefinition attribute of
@Column annotation:

<http://java.sun.com/javaee/5/docs/api/javax/persistence/Column.html#columnDefinition()>

What would be the equivalent columnDefinition for:
@Type(type="org.*hibernatespatial*.GeometryUserType")


TIA for your help.


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Karel Maesen
Administrator

On 12 May 2008, at 17:39, Farrukh Najmi wrote:

> Farrukh Najmi wrote:
>>
> But I do not know where the annotation class "Type" is defined. It  
> does
> not seem to be part of JPA.

The @Type annotation is  a Hibernate extension to the JPA annotations.

As I understand it, the JPA has no extensibility mechanism such as  
the Hibernate UserTypes. As far as I can see, this makes it  
impossible to persist spatial attributes with only JPA annotations.

See this discussion : http://www.theserverside.com/news/thread.tss?
thread_id=41886#216328.

Regards,

Karel Maesen
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Farrukh Najmi

Hi Karel,

Thanks for your kind help. I was able to use @Type from
hibernate-annotations and now I can have hibernate-spatial with postgis
dialect create the tables via hibernate entity manager for my spatial
Entity class.

However, when I run a test to persist the spatial entity class:

EntityManager em = ...
Object spatialObject = ...
em.persist(spatialObject);

I get the following exception:

java.lang.IllegalArgumentException: Unknown entity:
com.vividsolutions.jts.geom.Point
        at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:216)

I feel I am very close to success with using hibernate-spatial with JPA.
What am I missing?

TIA for your help.

Karel Maesen wrote:

> On 12 May 2008, at 17:39, Farrukh Najmi wrote:
>
>  
>> Farrukh Najmi wrote:
>>    
>> But I do not know where the annotation class "Type" is defined. It  
>> does
>> not seem to be part of JPA.
>>    
>
> The @Type annotation is  a Hibernate extension to the JPA annotations.
>
> As I understand it, the JPA has no extensibility mechanism such as  
> the Hibernate UserTypes. As far as I can see, this makes it  
> impossible to persist spatial attributes with only JPA annotations.
>
> See this discussion : http://www.theserverside.com/news/thread.tss?
> thread_id=41886#216328.
>  


--
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Farrukh Najmi

Doh! I just realized that I was sending the Geometry object to
em.persist instead of the JPA entity instance. Thanks Karel for setting
me straight.

Now that I am able to persist a spatial JPA entity, next I will learn
how to query it using spatial queries.

So here is my summary of what it took to use JPA so far:

0. Enable your postegres db to be postgis capable:

Unbuntu specific instructions:
<http://postgis.com/support/wiki/index.php?PostgisOnUbuntu>

1. Create an entity class with a Geometry (or sub-class property):


package org.freebxml.omar.jaxb.bindings.rim._4_0.geo;

import com.vividsolutions.jts.geom.Geometry;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.Type;


@Entity(name = "mypackage.GeometryValueType")
@Table(name = "GEOMETRYVALUETYPE")
public class GeometryValueType
{

    protected Geometry value;

    @Basic
    @Column(name="VALUE_",columnDefinition="GEOMETRY")
    @Type(type="org.hibernatespatial.GeometryUserType")  
    public Geometry getValue() {
        return value;
    }

    public void setValue(Geometry value) {
        this.value = value;
    }

}

2. Add your entity class to your persistence.xml

3. In your persistence.properties set hibernate.dialect as follows:

hibernate.dialect=org.hibernatespatial.postgis.PostgisDialect

Thanks again Karel for your help :-)


Karel Maesen wrote:

> Hi,
>
> Since the tables can be created by hibernate,  I guess the annotations
> are picked up properly by the entity manager. Despite this, the entity
> manager fails to use the information when persisting the object.
>
> Could you try to type the Object to the mapped class. So instead of:
>     Object spatialObject  = ...
>     em.persist(spatialObject);
>
> write:
>
>     <Classname of annotated class> spatialObject = ...
>     em.persist(spatialObject);
>
> If that doesn't help, could you provide me with the source code of the
> class you annotated?
>
> Regards,
>
> Karel
>
> On 14 May 2008, at 18:09, Farrukh Najmi wrote:
>
>> Hi Karel,
>>
>> I would be very grateful if you could please help me over this
>> hopefully simple bump.
>> Thanks.
>>
>>
>> Farrukh Najmi wrote:
>>> Hi Karel,
>>>
>>> Thanks for your kind help. I was able to use @Type from
>>> hibernate-annotations and now I can have hibernate-spatial with
>>> postgis dialect create the tables via hibernate entity manager for
>>> my spatial Entity class.
>>>
>>> However, when I run a test to persist the spatial entity class:
>>>
>>> EntityManager em = ...
>>> Object spatialObject = ...
>>> em.persist(spatialObject);
>>>
>>> I get the following exception:
>>>
>>> java.lang.IllegalArgumentException: Unknown entity:
>>> com.vividsolutions.jts.geom.Point
>>>         at
>>> org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:216)
>>>
>>>
>>> I feel I am very close to success with using hibernate-spatial with
>>> JPA. What am I missing?
>>>
>>> TIA for your help.
>>>
>>> Karel Maesen wrote:
>>>
>>>> On 12 May 2008, at 17:39, Farrukh Najmi wrote:
>>>>
>>>>
>>>>> Farrukh Najmi wrote:
>>>>>     But I do not know where the annotation class "Type" is
>>>>> defined. It  does
>>>>> not seem to be part of JPA.
>>>>>
>>>> The @Type annotation is  a Hibernate extension to the JPA annotations.
>>>>
>>>> As I understand it, the JPA has no extensibility mechanism such as  
>>>> the Hibernate UserTypes. As far as I can see, this makes it  
>>>> impossible to persist spatial attributes with only JPA annotations.
>>>>
>>>> See this discussion : http://www.theserverside.com/news/thread.tss?
>>>> thread_id=41886#216328.
>>>>
>>>
>>>
>>>
>>
>>
>> --
>> Regards,
>> Farrukh Najmi
>>
>> Web: http://www.wellfleetsoftware.com
>>
>>
>


--
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

fourat
Hi Farrukh,
Where did you get the com.vividsolutions.* package ?

regards
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Alexandre Walter Pretyman
Hi,

This package is from the JTS library - Java Topology Suite - http://sourceforge.net/projects/jts-topo-suite/ as stated on http://www.hibernatespatial.org/usage.html

Regards
Alexandre Pretyman

On Fri, Jul 9, 2010 at 10:18 PM, fourat <[hidden email]> wrote:

Hi Farrukh,
Where did you get the com.vividsolutions.* package ?

regards
--
View this message in context: http://hibernate-spatial.1140993.n2.nabble.com/Looking-for-sample-using-hibernate-spatial-with-JPA-tp1141163p5276611.html
Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Looking for sample using hibernate spatial with JPA

Farrukh Najmi
Hi,

I am using the following jar dependencies using maven dependency mechanism in my maven project:

    <dependency>
      <groupId>com.vividsolutions</groupId>
      <artifactId>jts</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
      <groupId>com.vividsolutions</groupId>
      <artifactId>jtsio</artifactId>
      <version>1.7</version>
    </dependency>


Here are jts*.jar url in ibiblio if you are using ant:

http://mirrors.ibiblio.org/pub/mirrors/maven2/com/vividsolutions/jts/1.8/jts-1.8.jar


I am having trouble finding the jtsio*.jar in a mven repo. Maybe I installed it manually in my local repo. Does any one know of the public maven repo where jtsio*.jar is available from?

On 07/10/2010 03:06 AM, Alexandre Pretyman wrote:
Hi,

This package is from the JTS library - Java Topology Suite - http://sourceforge.net/projects/jts-topo-suite/ as stated on http://www.hibernatespatial.org/usage.html

Regards
Alexandre Pretyman

On Fri, Jul 9, 2010 at 10:18 PM, fourat <[hidden email]> wrote:

Hi Farrukh,
Where did you get the com.vividsolutions.* package ?

regards
--
View this message in context: http://hibernate-spatial.1140993.n2.nabble.com/Looking-for-sample-using-hibernate-spatial-with-JPA-tp1141163p5276611.html
Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________ hibernatespatial-users mailing list [hidden email] http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users


-- 
Regards,
Farrukh

Web: http://www.wellfleetsoftware.com


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users