Galera, eu to precisando de ajuda pra achar os jars do hibernate! Eu ja baixei no site o Hibernate Core 3.3.0 SP1 mas não tem todos os jars que vi o pessoal aqui no guj falando que precisava. Tambem peguei os que vem com o mysql (tava falando num tutorial aqui no guj que tinha que pegar uns la). E mesmo assim ta faltand uns. Os que nao achei foram esses…
Eu uso o Hibernate 3.2 e todos estes JARs estao na lib dele. Acredito que pode ser o fato de vc ter baixado o Hibernate SP1, o SP1 deve ser apenas alguma atualizacao. Tenta baixar o normal.
Mas agora ta dando que nao consegue achar o get de uma classe. Sera que alguem pode ajudar?!
Eu to mandando em anexo os arquivos pra nao deixar o post tao grande.
O erro que ta dando é essse…
0 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1
16 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
141 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
141 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
297 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : br/com/bb/hbm/Usuarios.hbm.xml
453 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: br.com.bb.hibernate.Usuarios -> Usuarios
594 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : br/com/bb/hbm/Divisoes.hbm.xml
641 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: br.com.bb.hibernate.Divisoes -> Divisoes
641 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : br/com/bb/hbm/Gerencias.hbm.xml
Exception in thread "main" 688 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: br.com.bb.hibernate.Gerencias -> Gerencias
688 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
703 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: br.com.bb.hibernate.Divisoes.idDivisao -> Usuarios
703 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: br.com.bb.hibernate.Gerencias.idGerencia -> Divisoes
703 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
719 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
719 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
734 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/usuarios?autoReconnect=true
734 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****}
1141 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.0.51b-community-nt
1141 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
1172 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
1172 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
1172 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
1172 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1172 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1172 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1172 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: enabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
1188 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
1188 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
1188 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
1203 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: enabled
1203 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
1203 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
1203 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
1266 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
1641 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
1719 [main] ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: br.com.bb.hibernate.Divisoes, getter method of property: idDivisao
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of br.com.bb.hibernate.Divisoes.idDivisao
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:160)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:92)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:70)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:311)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
at Teste.main(Teste.java:27)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
... 19 more
Acho que não configurou direito o hibernate.cfg ou o hibernate.properties…veja qual vc usou e se está definido todas as classes utilizadas pelas tabelas…
As minhas unicas classes sao Usuarios, Divisoes e Gerencias. É um projeto pequeno só mesmo pra aprender a usar o hibernate. Mas as 3 estao mapeadas. Ou tem que fazer alguma coisa a mais do que isso?!
Algumas coisas que observei em seus arquivos
no arquivo de usuários
package br.com.bb.hibernate;
public class Usuarios {
private String matricula;
private String nome;
private String ramal;
private String senha;
//Quanto é chave estrangeira...utilize o objeto inteiro e não somente o id...
//fica assim
//private Integer idDivisao;
private Divisoes divisoes;
... getters e setters
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- Classe que referencia indicar o nome da tabela que a classe irá se relacionar-->
<class name="br.com.bb.hibernate.Usuarios" table="USUARIOS" lazy="false">
<!-- Chave primária Se é string não tem auto incremento -->
<id name="matricula" column="MATRICULA" type="java.lang.String" length="8">
</id>
<!--Propriedades da classe ----- definir coluna a que se refere tamanho, se é null, etc-->
<property name="nome" column="NOME" type="java.lang.String" length="50" not-null="true"/>
<!-- outros campos aqui-->
<many-to-one name="divisoes" class="br.com.bb.hibernate.Divisoes" column="IDDIVISAO"/>
</class>
</hibernate-mapping>
Nos outros arquivos tem que seguir o mesmo padrão de construção, isto é…se não usar anotattions