[code]Pessoal, estou fazendo uns testes utilizando a o hibernate spatial e postgis, pois estarei iniciando um projeto usando essas duas tecnologias em breve. E estou tendo problema para persistir dados geograficos. Eu consigo usar o hibernate para gerar as tabelas, com as colunas geograficas, porem não consigo persistir.
26/12/2009 13:31:32 org.hibernate.cfg.annotations.Version
INFO: Hibernate Annotations 3.3.1.GA
26/12/2009 13:31:32 org.hibernate.cfg.Environment
INFO: Hibernate 3.2.5
26/12/2009 13:31:32 org.hibernate.cfg.Environment
INFO: hibernate.properties not found
26/12/2009 13:31:32 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
26/12/2009 13:31:32 org.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
26/12/2009 13:31:33 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
26/12/2009 13:31:33 org.hibernate.connection.UserSuppliedConnectionProvider configure
WARNING: No connection properties specified - the user must supply JDBC connections
Exception in thread “main” org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at javaspatial.Main.main(Main.java:33)
Java Result: 1
[/code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package modelo;
import com.vividsolutions.jts.geom.Point;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.Type;
/**
*
* @author lucas
*/
@Entity
public class Evento implements Serializable {
@Id
@GeneratedValue
private long id;
private String descricao;
@Type(type="org.hibernatespatial.GeometryUserType")
@Column(columnDefinition="Point", nullable = true)
private Point ponto;
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Point getPonto() {
return ponto;
}
public void setPonto(Point ponto) {
this.ponto = ponto;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package util;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
*
* @author lucas
*/
public class GeraBanco {
public static void main(String args[]){
Configuration conf = new AnnotationConfiguration();
conf.configure();
SchemaExport se = new SchemaExport(conf);
se.create(true, true);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaspatial;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import modelo.Evento;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
/**
*
* @author lucas
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Evento evento = new Evento();
evento.setDescricao("Testando");
Geometry geom = null;
evento.setPonto((Point) geom);
Configuration conf = new AnnotationConfiguration();
SessionFactory sf = conf.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(evento);
tx.commit();
session.close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/teste</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">web</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<mapping class="modelo.Evento"/>
</session-factory>
</hibernate-configuration>