Olá a Todos,
Seguinte, estou usando o hibernate 3 com annotations, e to com algums problemas, vejam o meu código:
Classe Aluno.java
package syslagg.beans;
import javax.persistence.*;
@Entity(access=AccessType.FIELD)
@Table(name="Aluno")
public class Aluno{
@Id()
private int ra; // Ra do Aluno
@Column(name="nome", nullable=false, length=60)
private String nome; // Nome completo do Aluno
@Column(name="email", nullable=true, length=50)
private String email; // Endereço de e-mail
@Column(name="telefone", nullable=true, length=14)
private String telefone; // Telefone para contato
@Column(name="celular", nullable=true, length=14)
private String celular; // Celular para contato
@Column(name="curso", nullable=false, length=255)
private String curso; // Curso que faz
@Column(name="serie", nullable=false, length=1)
private String serie; // Série que cursa
@Column(name="campus", nullable=false, length=50)
private String campus; // Campus onde estuda
@Column(name="estagio", nullable=false)
@ManyToOne()
private int estagio; // Tipo de estágio
public void setRa (int ra){
this.ra = ra;
}
int getRa(){
return this.ra;
}
public void setNome (String nome){
this.nome = nome;
}
String getNome (){
return this.nome;
}
public void setEmail(String email){
this.email = email;
}
String getEmail(){
return this.email;
}
public void setTelefone(String telefone){
this.telefone = telefone;
}
String getTelefone(){
return this.telefone;
}
public void setCelular(String celular){
this.celular = celular;
}
String getCelular(){
return this.celular;
}
public void setCurso(String curso){
this.curso = curso;
}
String getCurso(){
return this.curso;
}
public void setSerie(String serie){
this.serie = serie;
}
String getSerie(){
return this.serie;
}
public void setCampus(String campus){
this.campus = campus;
}
String getCampus(){
return this.campus;
}
public void setEstagio (int estagio){
this.estagio = estagio;
}
@ManyToOne(cascade=CascadeType.MERGE)
public int getEstagio (){
return this.estagio;
}
}
Main.java
package syslagg;
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.hibernate.Session.*;
import org.hibernate.dialect.*;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
public class Main {
public static void main(String[] args) {
AnnotationConfiguration cfg = new AnnotationConfiguration();
// Configurando os Parametros
cfg.addAnnotatedClass(syslagg.beans.Aluno.class);
cfg.setProperty( "hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect" );
cfg.setProperty( "hibernate.connection.driver_class", "org.postgresql.Driver" );
cfg.setProperty( "hibernate.connection.url", "jdbc:postgresql:hibernate" );
cfg.setProperty( "hibernate.connection.username", "postgres" );
cfg.setProperty( "hibernate.connection.password", "kamikaze" );
cfg.setProperty( "hibernate.connection.autocommit", "true" );
cfg.setProperty( "hibernate.show_sql", "true" );
SessionFactory factory = cfg.buildSessionFactory();
SchemaUpdate update = new SchemaUpdate(cfg);
update.execute(true,true);
}
}
Vejam o erro:
init:
deps-jar:
Compiling 1 source file to D:\_Cainfu\SysLaGG\build\classes
compile:
run:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.Mappings.<init>(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;Ljava/util/List;Lorg/hibernate/cfg/NamingStrategy;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
at org.hibernate.cfg.ExtendedMappings.<init>(ExtendedMappings.java:42)
at org.hibernate.cfg.AnnotationConfiguration.createExtendedMappings(AnnotationConfiguration.java:72)
at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:44)
at syslagg.Main.main(Main.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
Valeu,
Paulo