Problema com hibernate [Resolvido]

8 respostas
wagnersf

Tento criar minha tabelas e dá o seguinte erro.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).

log4j:WARN Please initialize the log4j system properly.

Exception in thread main org.hibernate.MappingException: Could not determine type for: biblioteca.Livro, at table: Emprestimo, for columns: [org.hibernate.mapping.Column(idLivro)]

at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:290)

at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:164)

at org.hibernate.mapping.Column.getSqlType(Column.java:208)

at org.hibernate.mapping.Table.sqlCreateString(Table.java:419)

at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:930)

at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:129)

at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:91)

at bibliotecaDAO.GeraTabelas.main(GeraTabelas.java:17)

8 Respostas

otaviojava

dá uma olhada nas suas anotações
na classe Livro

Could not determine type for: biblioteca.Livro, at table: Emprestimo, for columns:

wagnersf

minha classe Livro está assim:

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;
@Entity

public class Livro {

@Id

@GeneratedValue

private Long id;
otaviojava

Se eu não me engano é necessário informar também a tabela
dá uma olhada neste exemplo. http://www.arquivodecodigos.net/dicas/hibernate-aprenda-a-usar-annotations-no-hibernate-3-2992.html

wagnersf

Continua com o mesmo erro.

C

Parece que o erro ta no relacionamento a Entidade Emprestimo, não está reconhecento o atributo idLivro que provavelmente está mapeada com o entidade Livro.
Verifique.

wagnersf

Consegui resolver o problema hehe

C

Intaum coloca a tag resolvido e posta sua solução para os demais que precisarem de ajuda.

flw

wagnersf

na minha classe Emprestimo coloquei:

@Entity
@Table(name=“emprestimos”)

public class Emprestimo {

@Id

@GeneratedValue

private Long id;
@OneToOne	
private Usuario usuario;
@OneToOne
    private Livro livro;

a unica coisa que faltava era o @OneToOne

Criado 17 de maio de 2011
Ultima resposta 17 de mai. de 2011
Respostas 8
Participantes 3