(Resolvido)DUVIDA HIBERNATE

8 respostas
O

opa pessoal

estou tentando botar o hibernate pra roda mas to encontrando algumas dificuldades:

quando eu compilo o código aparece a seguinte mensagem:
[i]

09:55:04,593  INFO Environment:514 - Hibernate 3.2.6

09:55:04,593  INFO Environment:547 - hibernate.properties not found

09:55:04,609  INFO Environment:681 - Bytecode provider name : cglib

09:55:04,609  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling

09:55:04,656  INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml

09:55:04,656  INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml

09:55:04,921  INFO Configuration:559 - Reading mappings from resource : Hiber/Amigos.hbm.xml

09:55:06,171  INFO HbmBinder:300 - Mapping class: Hiber.Amigos -> amigos

09:55:06,187  INFO Configuration:1547 - Configured SessionFactory: null

09:55:06,281  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)

09:55:06,281  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1

09:55:06,296  INFO DriverManagerConnectionProvider:45 - autocommit mode: false

09:55:06,312  INFO DriverManagerConnectionProvider:80 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432

09:55:06,312  INFO DriverManagerConnectionProvider:86 - connection properties: {user=postgres, password=****}

09:55:06,406  INFO SettingsFactory:89 - RDBMS: PostgreSQL, version: 8.3.0

09:55:06,406  INFO SettingsFactory:90 - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 506)

09:55:06,421  INFO Dialect:152 - Using dialect: org.hibernate.dialect.HSQLDialect

09:55:06,437  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)

09:55:06,437  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)

09:55:06,437  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled

09:55:06,437  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled

09:55:06,437  INFO SettingsFactory:154 - JDBC batch size: 15

09:55:06,437  INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled

09:55:06,453  INFO SettingsFactory:162 - Scrollable result sets: enabled

09:55:06,453  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled

09:55:06,453  INFO SettingsFactory:178 - Connection release mode: auto

09:55:06,453  INFO SettingsFactory:205 - Default batch fetch size: 1

09:55:06,453  INFO SettingsFactory:209 - Generate SQL with comments: disabled

09:55:06,453  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled

09:55:06,453  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled

09:55:06,453  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory

09:55:06,453  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory

09:55:06,453  INFO SettingsFactory:225 - Query language substitutions: {}

09:55:06,453  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled

09:55:06,453  INFO SettingsFactory:235 - Second-level cache: enabled

09:55:06,453  INFO SettingsFactory:239 - Query cache: disabled

09:55:06,453  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider

09:55:06,453  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled

09:55:06,453  INFO SettingsFactory:263 - Structured second-level cache entries: disabled

09:55:06,468  INFO SettingsFactory:283 - Echoing all SQL to stdout

09:55:06,468  INFO SettingsFactory:290 - Statistics: disabled

09:55:06,468  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled

09:55:06,468  INFO SettingsFactory:309 - Default entity-mode: pojo

09:55:06,468  INFO SettingsFactory:313 - Named query checking : enabled

09:55:06,500  INFO SessionFactoryImpl:161 - building session factory



Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: Hiber/Amigos (wrong name: hiber/Amigos)

Exception in thread main java.lang.ExceptionInInitializerError

at hiber.AmigosDAO.(AmigosDAO.java:19)

at Hiber.Gerenciadora.createAndStoreEvent(Gerenciadora.java:22)

at Hiber.Gerenciadora.main(Gerenciadora.java:15)

Caused by: java.lang.NoClassDefFoundError: Hiber/Amigos (wrong name: hiber/Amigos)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:620)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)

at java.net.URLClassLoader.access$100(URLClassLoader.java:56)

at java.net.URLClassLoader$1.run(URLClassLoader.java:195)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)

at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)

at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)

at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)

at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:124)

at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:434)

at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:109)

at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)

at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:226)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)

at hiber.AmigosDAO.(AmigosDAO.java:15)

 2 more

Java Result: 1

BUILD SUCCESSFUL (total time: 2 seconds)

[/i]
eu creio q o erro está mesmo na linha:

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: Hiber/Amigos (wrong name: hiber/Amigos)

Exception in thread “main” java.lang.ExceptionInInitializerError

pelo que eu entendi ele não está encontrando a classe Hiber/Amigos que está declarada no arquivo hibernate.cfg.xml na clausula mapping resource
assim como abaixo:

sera que há um problema na estrutura de diretorios??
pq sera q o hibernate nao esta encontrando este arquivo??
quem puder ajudar eu agredeco

8 Respostas

O

só pra deixar mais claro o arquivo hibernate.cfg.xml esta na mesma pasta que o package Hiber que contem o arquivo de mapeamento Amigos.hbm.xml e os demais arquivos java das classes

fbeli

acho q vc pode colocar direto no Amigos, sem o Hiber/

Testa seu hibernate.cfg na raiz e coloca todos os seus .hbm.xls junto. Assim vc memso pode ir mapeando o erro

albertoleal

o arquivo “hibernate.properties” deve ficar na raiz do projeto.

rdantas

posta seu código e a config do hibernate. Talvez isso ajude-nos a te ajudar…

felipedamiani

coloque o hibernate.cfg.xml no diretório “src” do seu projeto

O

puts eu coloquei o arquivo hibernate.cfg.xml na pasta src do projeto e mudei a tag mapping resource para

e continua dando o mesmo erro:
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: Hiber/Amigos (wrong name: hiber/Amigos)
Exception in thread "main" java.lang.ExceptionInInitializerError

vou postar o codigo do arquivo hibernate.cfg.xml pra vcs darem uma olhada
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">161086</property>
       
       <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>


        <mapping resource="Amigos.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

entao nao sei se este arquivo esta correto eu dei uma olhada em outros arquivos do tipo no google mas nao tenho uma referencia correta
o banco que eu to usando é o portgresql

O

classe que faz a conexao:

package hiber;

import org.hibernate.*;
import org.hibernate.cfg.*;




public class AmigosDAO {
    private static final SessionFactory factory;
    
    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            factory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return factory;
    }
}
O

noossa o problema era ridiculo, mudei o nome do package e esqueci de referencia o novo nome nas classes.
q vacilo!!!
mas valeu pela ajuda
e se ainda tiverem comentarios sobre o hibernate.sfg.xml vai ajudar

Criado 4 de março de 2008
Ultima resposta 4 de mar. de 2008
Respostas 8
Participantes 5