Hi!
The error is..
Code:
init:
deps-jar:
Compiling 1 source file to /home/bruno/NetBeansProjects/IntroducaoHibernate01/build/classes
compile:
run:
03/10/2009 00:11:42 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
03/10/2009 00:11:42 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
03/10/2009 00:11:42 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
03/10/2009 00:11:42 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
03/10/2009 00:11:42 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
03/10/2009 00:11:42 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
03/10/2009 00:11:42 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
03/10/2009 00:11:42 org.hibernate.cfg.AnnotationConfiguration addPackage
INFO: Mapping package introducaohibernate01
03/10/2009 00:11:42 org.hibernate.cfg.AnnotationBinder bindPackage
WARNING: Package not found or wo package-info.java: introducaohibernate01
03/10/2009 00:11:42 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
03/10/2009 00:11:42 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: introducaohibernate01.Pessoa
03/10/2009 00:11:42 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity introducaohibernate01.Pessoa on table pessoa
Initial SessionFactory creation failed.Unknown Id.generator: codigo_seq
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:30)
at introducaohibernate01.ProfessorDAO.salvarProfessor(ProfessorDAO.java:17)
at introducaohibernate01.Main.main(Main.java:38)
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: codigo_seq
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:428)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1908)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1281)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:534)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at util.HibernateUtil.<clinit>(HibernateUtil.java:26)
... 2 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo)
Pessoa class
Code:
@Entity
@Table(name="pessoa")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Pessoa implements Serializable {
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "codigo_seq")
@SequenceGenerator(name = "codigo_seq", sequenceName = "codigo_seq", allocationSize =1)
@Id
@Column
private Integer codigo;
My Professor class
Code:
@Entity
@Table(name="professor")
public class Professor extends Pessoa {
@PrimaryKeyJoinColumn(name="matProfessor")
@Column (name = "mat_professor")
private Integer matProfessor;
My Aluno class
Code:
@Entity
@Table(name="aluno")
public class Aluno extends Pessoa {
@PrimaryKeyJoinColumn(name="matAluno")
@Column (name = "mat_aluno")
private Integer matAluno;
My SQL code on PostgreSQL 8.3:
Code:
create table pessoa (
codigo serial not null,
nome varchar(80) not null,
data_nascimento varchar(9) not null,
email varchar(45) not null,
endereco varchar(100) not null,
telefone varchar(20) not null,
cpf varchar(12) not null,
identidade varchar(15) not null,
constraint pk_codigo primary key (codigo)
);
create table aluno(
mat_aluno integer not null,
ano_inicio varchar(4) not null,
semestre_inicio integer not null,
constraint pk_mat_aluno primary key (mat_aluno)
) inherits (pessoa);
create table professor(
mat_professor integer not null,
titulacao_maxima varchar(45) not null,
constraint pk_mat_professor primary key (mat_professor)
) inherits (pessoa);
when I insert the data by postgre, works perfectly, but hibernate appears this error.
can anyone help?