[postgis-users] SpatialEJB3: (PostGIS and Hibernate)

Norman Barker nbarker at ittvis.com
Tue Dec 19 00:22:08 PST 2006


Hi Andrew,

What you are saying is correct, but I will expand on it just to be clear
for you and others.

You have to add the GeometryType to your project, and postgis.jar, and
postgresqlXx.jar to the JBoss path (JBOSS_HOME\server\default\lib for
example).

It is then sufficient to mark a geometry getter of a POJO (with the
@Entity annotation at the class level) as 	

@Type(type = "org.postgis.hibernate.GeometryType")
@Column(name="bbox", columnDefinition="Geometry")   (name can be
whatever you want, or you can leave it to hibernate to choose it for you
:-) )

Then in your stateless session bean you can inject the entityManager 

	@PersistenceContext(unitName="MyConfiguration")
	private EntityManager entityManager;

and persist your entity pojos as per normal.

If you configure your persistence.xml as follows then the PostGIS tables
of your spatial database are created for you (can be a good or a bad
thing depending on your view point, you have to add the spatial index by
hand).

<persistence>
	<persistence-unit name="MyConfiguration">
		<jta-data-source>java:/MY_DS</jta-data-source>
		<properties>
			<property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect"/>
			<property name="hibernate.hbm2ddl.auto"
value="update"/>
			<!-- property name="hibernate.show_sql"
value="true"/>  -->
		</properties>
	</persistence-unit>
</persistence>

Hope this gets you started, please post your findings back to the list.

Thanks,

Norman

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Andrew Hughes
Sent: 19 December 2006 02:05
To: PostGIS Users Discussion
Subject: Re: [postgis-users] SpatialEJB3: (PostGIS and Hibernate)

Hi Norman,

Thanks very much for the reply. Originally I noticed that this was an 
eclipse project, so I tried to get it to compile in Eclipse.... however 
this failed (and I made the wrong assumption that I needed the JBoss IDE

plugins installed).

Anyway, I have tried this with Ant directly and I now have this 
compiling.. and building the injest.jar.

I don't want to use the message driven beans as in the tutorial... or 
SOAP,  I am using stateless session beans, currently with PostgreSQL... 
but I obviously want to add the Geometry Type to the hibernate actions.

I am correct in assuming that I simply need to add the GeometryType.java

class to my project to enable this? I would then use annotations to 
specify the GeometryType such as:

@Type(type = "org.postgis.hibernate.GeometryType")

Is there anything that I am missing?

Thanks in advance

--AH



Norman Barker wrote:
> Hi Andrew,
>
> Hopefully this gets to you before you start downloading the JBoss IDE!
>
> The project uses Ant, and the Java 1.5 JDK.
>
> (http://ant.apache.org)
> (http://svn.refractions.net/postgis/trunk/java/ejb3/build.xml)
>
> If you edit the paths in build.xml to point to your installation,
> running 'ant deploy' will build and deploy everything to JBoss for
you.
> I used to use the JBoss IDE in the XDoclet for EJB2.x days, but with
> annotations I have dumped it for plain eclipse - but perhaps I should
> give it a go.
>
> Norman
>
>   
>
> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net
> [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
> Andrew Hughes
> Sent: 18 December 2006 05:48
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] SpatialEJB3: (PostGIS and Hibernate)
>
> Thanks for the reply....
>
> I have checked out the EJB3Spatial source from SVN: 
> http://svn.refractions.net/postgis/trunk/java/ejb3/
>
> Now, I am presuming that this requires the JBoss IDE? since it doesn't

> build with Eclipse.... and I can't see this anywhere in the tutorial.
>
> The JBoss plugins are in total 119Mb.... which is rather painful and 
> slow... it would be rather helpful if the binaries where available for

> direct download.
>
>
> When I finally get this downloaded I'll hopefully make some good
> progress :)
>
>
>
>
> Norman Barker wrote:
>   
>> Hi,
>>
>> Glad you like the idea! PostGIS does all the work though J, and there

>> have been some good bug reports and questions from users as well.
>>
>> In conclusion;
>>
>> There have been quite a few users of the EJB3 Geometry annotations, 
>> but they are split between JBoss users, and pure Hibernate/Spring 
>> users - it works well in either environment. Since it is possible to 
>> mark a property of an entity as @Geometry and then have it persist
and
>>     
>
>   
>> retrieve from PostGIS then the investigation was a success, and I am 
>> using it in more projects (and once my current deadlines are out of 
>> the way, I want to do some more to the codebase).
>>
>> The incorporation of spatial functions into hql and ejb-ql is I 
>> believe the next step, but quite a major undertaking. Certainly at
the
>>     
>
>   
>> moment you could achieve the same functionality with 
>> entitymanager.createNativeQuery for example (which I use to run
vacuum
>>     
>
>   
>> analyze).
>>
>> Let me know if you have any questions, and do post more details about

>> your project, there have been some interesting use cases.
>>
>> Thanks,
>>
>> Norman
>>
>>
>>     
>
------------------------------------------------------------------------
>   
>> *From:* postgis-users-bounces at postgis.refractions.net 
>> [mailto:postgis-users-bounces at postgis.refractions.net] *On Behalf Of 
>> *Andrew Hughes
>> *Sent:* 12 December 2006 04:39
>> *To:* PostGIS Users Discussion
>> *Subject:* [postgis-users] SpatialEJB3: (PostGIS and Hibernate)
>>
>> Hello All,
>>
>> I would like to use the SpatialEJB3 JBoss container for my JBoss Web 
>> Service.
>>
>> The SpatialEJB3 [ 
>> http://postgis.refractions.net/support/wiki/index.php?SpatialEJB3 ] 
>> seems to be exactly what I want, but I do have some concerns before I

>> invest some time in this.....
>>
>>     * Was there a conclusion to the SpatialEJB3 Investigation:
>>       "/Spatial EJB3 is a quick investigation to see if it is
possible
>>       to integrate the Java 5 annotation approach to mark a property
>>       of an object as spatial and to delegate to the EJB3 persistence
>>       model to store and retrieve this data./"?
>>     * I require the PostGIS functions [such as
>>       /intersects(geometry,geometry)/] to extract the data I am
>>       looking for in my spatial database. I am unable to find a
>>       reference to any java code that shows someone running anything
>>       [like /select intersection(my_geom,geometry) from
>>       locations_table where intersects(my_geom,geomtery);/ ] ?
>>
>>
>> For the people who are involved in the Spatial EJB3, I really like
the
>>     
>
>   
>> idea... well-done!!!
>>
>>
>> --AH
>>
>>
>>     
>
------------------------------------------------------------------------
>   
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>   
>>     
>
>
>   


-- 

Regards,

*Andrew Hughes*
Software Engineer
LISAsoft Pty. Ltd. (Adelaide)

------------------------------------------------------------------------


      LISAsoft Pty. Ltd.

<http://www.lisasoft.com>
*ADELAIDE Office*
<http://terrapages.net/mapbutton/RetrieveButtonServlet?buttonID=4>
38 Greenhill Road
Wayville SA 5034
Australia
*Telephone +61 8 8272 1555*
*Facsimile +61 8 8271 1199* 	
	*SYDNEY Office*
<http://terrapages.net/mapbutton/RetrieveButtonServlet?buttonID=1>
Suite 112 The Lower Deck
Jones Bay Wharf
19-21 Pirrama Road
Pyrmont NSW 2009 AUS
*Telephone +61 2 8570 5060*
*Facsimile +61 2 8570 5099* 	
	*MELBOURNE Office*
<http://terrapages.net/mapbutton/RetrieveButtonServlet?buttonID=3>
Level 7 520 Collins Street
Melbourne VIC 3000
Australia
*Telephone +61 3 9629 1799*
*Facsimile +61 3 9629 4955*

------------------------------------------------------------------------
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list