[postgis-users] Hibernate with PostGIS

Jan Syryn jan.syryn at trasys.be
Wed Nov 22 09:14:36 PST 2006


Yes indeed, Hibernate has the possibility to create a schema for you.
And yes, it is practical, I used it also.
But the problem is, it is not well done.
For example: the name of the PK en FK indices are random. Not nice if you
have a fk144524524541 contraint exception 
Also when you execute your code, you will also loose all your data already
inserted before. (he creates new tables).
So I used it once, cleaned the schema and never uses it again.
 
What is your status exactly ? Do you succeed in inserting an object (without
PostGis data) into your DB ?
 
It is possible (and probably true) that Hibernate is not capable of creating
a Geometry column itself.
But what is the use or benefit ? Very limited.
 
Like I said: 
- make a working version without Geometry (with the auto-creation feature if
you want). 
- remove the auto-creating feature
- Add a column yourself in db that is of type Geometry
- try to insert a POJO that also contains the Geometry.
 
Try to keep it simple !
 
Jan

  _____  

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Sandeep
Kumar Jakkaraju
Sent: mercredi 22 novembre 2006 16:10
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Hibernate with PostGIS


Hello Jan ..

Thanks for ur reply .. u r right i am newbie in Hibernate and Spring !! 

I thought that creating table schema automatically is a GOOD feature of
Hibernate ..

For example:-

If your application is using some tables .. u create those tables in your db
.. 
but when u want to use some other db ..u have to send all the sql scripts
with schema.. and some has to run it ...to create the table schemas... 
But If you u r using hibernate ...there is no need for this ..because it
automatically creates the table schemas .. 

Please correct do me ..if my argument is wrong ..

With Hibernate-PostGIS .. it is not able to create the Geometry column
automatically .. i thought it was BUG which needed attention .. so i posted
it ... 

I have no other problem with using Hibernate with postgis ....

I really appreciate  ur other suggestions as well..

Thanks 
Regards
Sandeep




On 11/22/06, Jan Syryn <jan.syryn at trasys.be> wrote: 

Hi Sandeep,

 
I am also doing a project with PostgresSQL/PostGIS and Hibernate.
 
In general: it seems that you are lacking a common knowledge of Hibernate in
general and that you problems are merely related to Hibernate than to
PostGIS.
 
In a normal Hibernate situation, you don't need to create the database
schema automatically, so you should not use the property hbm2dll.auto.
I propose you leave it out of you config file.
You just create the Geometry column in your table of the DB.
Also, it is a good practice to add a constructor to your POJO objects This
helps of easely creating objects that need to persisted in the database 
 
 
Little suggestion: 
- make the geometry column nullable. With the correction of Dave you should
be able of doing so with the GeometryUserType.
- Add for exemple an extra 'name' field to your table.
- Try to add a line in your DB without the geometry column. 
for exemple: 
      session.save(new RoadNetwork("sandeep"))
This way, you know a) your keygenerator works b) a session is well
intantiated c) transaction did work
- If this goes well, try to use the postgis component:
 
      Geometry myGeom = factory.createGeometry();
      session.save(new RoadNetwork("sandeep",myGeom))
 
HIH (I hope it helps), 
Jan
 
PS: I am also using Spring. But this is not your problem. The use of Spring
only complicate the things. Try to get the thing fired as simple as
possible. Then start building things up from there.

  _____  

From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Sandeep
Kumar Jakkaraju
Sent: samedi 18 novembre 2006 15:54
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Hibernate with PostGIS




I think Hibernate cannot create that Geometry column automatically !!! 
is it something to do with hbm2ddl.auto !! 


I am able to ..get the geometry from a table with geometry column already
created ...

Norman -->> Would you like me to create a simple tutorial on how to use
Hibernate with Postgis ..your tutorial .. is not easy to understand ...


Thanks
Sandeep





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







-- 
Sandeep Kumar Jakkaraju 
WeBlog:
http://jakkarajus.blogspot.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20061122/78114817/attachment.html>


More information about the postgis-users mailing list