Olá Pessoal
Estou tentando aprender a trabalhar com o Hibernate, consegui fazer tupo, o mapeamento, gerar a tabela na base de dados, porém quando mando rodar o programa, ele da um erro dizendo q o dialect não está setado, obs.: estou usando o Netbeans 4.1, Hibernate3 e como banco o PostgreSQL.
Ai vai os códigos:
/*
* Produto.java
*
* Created on 18 de Maio de 2005, 15:34
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
/**
*
* @author Usuario
*/
/**
* Classe Modelo para um produto
* @hibernate.class table="produto"
*/
public class Produto {
private Long id;
private String nome;
private String descricao;
private Double preco;
public void setId(Long id){
this.id = id;
}
/**
* @hibernate.id generator-class="native"
*/
public Long getId(){
return this.id;
}
public void setNome(String nome){
this.nome = nome;
}
/**
* @hibernate.property not-null="true"
*/
public String getNome(){
return this.nome;
}
public void setDescricao(String descricao){
this.descricao = descricao;
}
/**
* @hibernate.property
*/
public String getDescricao(){
return this.descricao;
}
public void setPreco (Double preco){
this.preco = preco;
}
/**
* @hibernate.property
*/
public Double getPreco(){
return this.preco;
}
}
Produto.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="Produto"
table="produto"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Produto.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
column="nome"
not-null="true"
/>
<property
name="descricao"
type="java.lang.String"
update="true"
insert="true"
column="descricao"
/>
<property
name="preco"
type="java.lang.Double"
update="true"
insert="true"
column="preco"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Produto.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Hibernate.Properties
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/lagg1
hibernate.connection.username = postgres
hibernate.connection.password = kamikaze
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
Main.java
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
public class Main {
public static void main(String args[]){
try{
Configuration cfg = new Configuration().addClass(Produto.class);
SessionFactory factory = cfg.buildSessionFactory();
factory.close();
} catch (org.hibernate.HibernateException e){
e.printStackTrace();
e.getMessage();
}
}
}
e o erro que o compiler encontra
run:
(cfg.Environment 460 ) Hibernate 3.0
(cfg.Environment 473 ) hibernate.properties not found
(cfg.Environment 506 ) using CGLIB reflection optimizer
(cfg.Environment 536 ) using JDK 1.4 java.sql.Timestamp handling
(cfg.Configuration 460 ) Mapping resource: Produto.hbm.xml
(cfg.HbmBinder 258 ) Mapping class: Produto -> produto
(cfg.Configuration 851 ) processing extends queue
(cfg.Configuration 855 ) processing collection mappings
(cfg.Configuration 864 ) processing association property references
(cfg.Configuration 893 ) processing foreign key constraints
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:477)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:499)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:51)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
at Main.main(Main.java:28)
BUILD SUCCESSFUL (total time: 1 second)
Se alguém puder me ajudar.
T+
Paulo
