Erro ao gravar algo na aplicação com hibernate

30 respostas
B

Pessoal segue o erro ao gravar:

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use

Alguém pode dar uma força.

grato.

30 Respostas

P

Cara, esse mapeamento seu tá meio estranho.

<mapping class="org.classes.hello.Setor.class"/>

A classe chama class?

se não tente assim:

<mapping class="org.classes.hello.Setor"/>
RobsonFagundes

veja…
= colega prbpedro disse… verifique seu arquivo hibernate.cfg.xml
vc ta com erro na tag

<mapping class="Sua Classe"/>

look:
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/

T+

B

Na verdade estava assim antes mas tentei de forma diferente mas não tive exito, eu não estou usando os arquivos hbm, pode ser tudo no hibernate.cfg.xml estou correto?

B

O caminho do pacote esta correto:

mas continua com o mesmo erro: An AnnotationConfiguration instance is required to use

não sei se esta faltando algo no meu arquivo xml.

RobsonFagundes

Boby
posta ele ai …

B

é esse ai:

com.mysql.jdbc.Driver jdbc:mysql://localhost/banco_toner root 12345678
<!--poll de conexões-->
    <property name="hibernate.conection.poll_size">10</property>
    
    <!--SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    
    <mapping class="org.classes.hello.Setor"/>
</session-factory>
RobsonFagundes

tenta fazer o seguinte :

troque o a tag mapping de:

<mapping class="org.classes.hello.Setor"/>

para:

<mapping class="org.classes.hello.Setor" file="SEU.hbm.xml" />
ou

<mapping class="org.classes.hello.Setor" resource="SEU.hbm.xml" />

T+

RobsonFagundes

Boby
tenta assim tmb…

<mapping resource="org.classes.hello.Setor"/>

T+

B

Ai esta o problema não sei se leu as mensagens anteriores, eu não quero usar os arquivos hbm, só o arquivo hibernate.cfg.xml, tem como?

grato.

B

RobsonFagundes

usando o “resource” eu também já usei, mas acho que isso é pra usar com os hbm.

RobsonFagundes

teria se vc usar annotations…
pq dai o relacionamentos das classes ficariam no Bean por ex

@Entity
@Table(name = "setor")
public class Setor implements Serializable {
  // atributos
  // seter  & geters
}

e nao no arquivo HBM … ok
T+

B

Colega estou usando annotation, vou colocar a minha classe pra vc analisar:

@Entity

@Table(name = setor)

public class Setor implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "idSetor")
private Integer idSetor;
@Column(name = "nome")
private String nomeSetor;

public Integer getIdSetor() {
    return idSetor;
}

public void setIdSetor(Integer idSetor) {
    this.idSetor = idSetor;
}

public String getNomeSetor() {
    return nomeSetor;
}

public void setNomeSetor(String nomeSetor) {
    this.nomeSetor = nomeSetor;
}

}

RobsonFagundes

esta sua classe se relaciona com outras ???
pq dai faltaria a tag

@OneToOne
@OneToMany

por ex se ela se relacionar com funcionario ficaria algo assim

@OneToMany(cascade = CascadeType.ALL, mappedBy = "setorIdasso")
    private Collection<Funcionario> funcionarioCollection;
RobsonFagundes

use tmb a tag do bean Setor

@Id
@GeneratedValue(strategy = GenerationType.AUTO)

por

@Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)

T+

B

Essa classe ou seja a tabela setor não tem nenhuma chave estrangeira, mas tabela impressora se relaciona com Setor, não sei se é isso que vc me perguntou.

RobsonFagundes
sim sim isso mesmo tá deixa te mostrar um exemplo de hibernate.cfg so que é para postgres ok...
<hibernate-configuration>
    <session-factory>
        
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        
    <!--<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.126:5432/sicbd</property>-->
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/avisuipar</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">my pws</property>
     
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.format_sql">true</property>
        <property name="hibernate.transaction.flush_before_completion">true</property>
        <property name="hibernate.transaction.auto_close_session">true</property>
        
        <mapping class="pojo.Associado"/>
        <mapping class="pojo.Endereco"/>
        <mapping class="pojo.Conjuge"/>
        <mapping class="pojo.Dependentes"/>
        <mapping class="pojo.Propriedades"/>
        
        
    </session-factory>
</hibernate-configuration>

outra coisa vc possui o arquivo log4j.properties junto com o hibernate.cfg ????

B

Pois é esse arquivo log4j da um warning reclamando que não inicializei.

RobsonFagundes

hammmmmm claro !!!
ja sei aonde ta o erro …
cola ai no seu log4j

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE}%5p %c{1}:%L - %m%n

# Root logger option'
log4j.rootLogger=INFO, stdout

# Hibernate logging options (INFO only shows startup messages)
log4j.logger.org.hibernate=INFO

# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=INFO

# Log HibernateUtil
log4j.logger.helper=INFO
log4j.logger.dao=INFO

agora da certo …
tenta ai e avisa ok
T+

B

amigo não me leva a mal, mas eu não sei onde esta esse arquivo eu não criei nenhum arquivo com esse nome, ele vem com o pacote do annotations.

RobsonFagundes

ta faiz assim… na raiz do seu projeto ou no mesmo pacote aonde esta o hibernate.cfg.xml
crie um arquivo do tipo proprierties com o nome de log4j e cole as tags acima dentro dele…
vc usa Netbeans ou Eclipse ???w

B

Uso netbeans…

RobsonFagundes

se ele estiver em portugues…
na raiz do projeto …
Novo => Outro =>Outro => Arquivo de Propiedades
de o nome a ele de:log4j
tente…

B

Criei o arquivo e quando rodei deu o seguinte erro:

17/12/2008 17:29:48 org.apache.catalina.core.StandardContext reload

INFO: Reloading this Context has started

17:29:56,146 INFO Environment:509 - Hibernate 3.2.2

17:29:56,146 INFO Environment:542 - hibernate.properties not found

17:29:56,146 INFO Environment:676 - Bytecode provider name : cglib

17:29:56,162 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling

17:29:56,224 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml

17:29:56,224 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml

17:29:56,302DEBUG DTDEntityResolver:38 - trying to resolve system-id [<a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a>]

17:29:56,302DEBUG DTDEntityResolver:40 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/

17:29:56,302DEBUG DTDEntityResolver:50 - located [<a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd</a>] in classpath

17:29:56,349DEBUG Configuration:1387 - hibernate.conection.driver_class=com.mysql.jdbc.Driver

17:29:56,349DEBUG Configuration:1387 - hibernate.conection.url=jdbc:mysql://localhost/banco_toner

17:29:56,365DEBUG Configuration:1387 - hibernate.conection.username=root

17:29:56,365DEBUG Configuration:1387 - hibernate.conection.password=12345678

17:29:56,365DEBUG Configuration:1387 - hibernate.conection.poll_size=10

17:29:56,365DEBUG Configuration:1387 - dialect=org.hibernate.dialect.MySQLDialect

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use 

at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1600)

at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)

at org.classes.hello.HibernateUtil.(HibernateUtil.java:20)

at org.classes.hello.SetorDao.insert(SetorDao.java:21)

at org.mypackage.hello.cadastraSetorServlet.processRequest(cadastraSetorServlet.java:58)

at org.mypackage.hello.cadastraSetorServlet.doPost(cadastraSetorServlet.java:107)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Thread.java:595)
RobsonFagundes

vc add os jars na lib do projeto ???

ejb3-persistence.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
log4j-1.2.11.jar
c3p0-0.9.1.jar
B

Esse dois não estão no lib:
hibernate-commons-annotations.jar
hibernate-core.jar

vou colocar e testar.

RobsonFagundes

coloca tmb o

cglib-2.1.3.jar
c3p0-0.9.1.jar 
jta.jar
log4j-1.2.15.jar

pra garantir hehehehehhe
t+

B

Velho da o mesmo erro ta complicado.

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use

mas o warning do log4j não da mais

RobsonFagundes

puts…
tenta da uma olhada nestes posts aki pra ver se ajuda…

http://www.guj.com.br/posts/list/15/32225.java
http://www.javafree.org/javabb/viewtopic.jbb?t=866972#148655
http://opensource.atlassian.com/projects/hibernate/browse/HBX-980
http://lists.jboss.org/pipermail/hibernate-issues/2007-August/006704.html


http://forum.mentaframework.org/posts/list/2089.page
T+

B

Agradeço pela força velho vou procurar.

grato

B

Seguinte agora esta dando esse erro:

SEVERE: Servlet.service() for servlet cadastraSetorServlet threw exception java.lang.NoClassDefFoundError

o erro de annotations consegui arrumar, era problema na minha classe HibernateUtil.

Criado 17 de dezembro de 2008
Ultima resposta 19 de dez. de 2008
Respostas 30
Participantes 3