Boa tarde a todos!
É o seguinte pessoal! Estou estudando o Hibernate, e depois de muito queimar a mufa minimizei (???) os problemas por aqui mas ainda não consegui vê-lo funcionar. Depois de garimpar e testar varios tutoriais pela net, aqui estou.
Criei um Projeto Java e na raiz do src coloquei os arquivos hibernate.cfg.xml, log4j.properties e Produto.hbm.xml (penso que este vai criar minha tabela no banco, mapeada de acordo com a minha classe java). O conteúdo desses 3 arquivos está abaixo.
Criei uma pasta lib na raiz do projeto e copiei para dentro dela os seguintes .jars:
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate-jpa-2.0-api-1.0.0.final.jar
hibernate3.jar
javassist-3.12.0.GA.jar
jaybird-full-2.1.6.jar (meu banco é firebird 2.5)
jta-1.1.jar
log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
OBS: Quando eu registro estas .jars via Build path o hibernate (?) faz uma
duplicação delas na raiz do projeto.
Pelo que entendi cada classe “DAO” terá que ter seu respectivo xxx.hbm.xml que será responsável pela criação do objeto tabela no
banco, certo ?
--------- ARQUIVO hibernate.cfg.xml
<!-- local connection properties -->
<property name="connection.driver_class">org.firebirdsql.jdbc.FBDriver</property>
<property name="connection.url">jdbc:firebirdsql:localhost/3050:D:\MEUBANCO.fdb</property>
<property name="connection.username">SYSDBA</property>
<property name="connection.password">masterkey</property>
<property name="dialect">org.hibernate.dialect.FirebirdDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
</session-factory>
---------- ARQUIVO log4j.properties
Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=d:\hibernateapp.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
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, file, stdout
Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO
Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL
-------- ARQUIVO Produto.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>-------- ARQUIVO de log Gerado quando Run Application na classe Produto
14:31:39,030 DEBUG BasicTypeRegistry:147 - Adding type registration boolean -> org.hibernate.type.BooleanType@c7e553
14:31:39,033 DEBUG BasicTypeRegistry:147 - Adding type registration boolean -> org.hibernate.type.BooleanType@c7e553
14:31:39,033 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@c7e553
14:31:39,036 DEBUG BasicTypeRegistry:147 - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@53ba3d
14:31:39,037 DEBUG BasicTypeRegistry:147 - Adding type registration true_false -> org.hibernate.type.TrueFalseType@1813fac
14:31:39,038 DEBUG BasicTypeRegistry:147 - Adding type registration yes_no -> org.hibernate.type.YesNoType@136228
14:31:39,041 DEBUG BasicTypeRegistry:147 - Adding type registration byte -> org.hibernate.type.ByteType@84abc9
14:31:39,041 DEBUG BasicTypeRegistry:147 - Adding type registration byte -> org.hibernate.type.ByteType@84abc9
14:31:39,042 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Byte -> org.hibernate.type.ByteType@84abc9
14:31:39,044 DEBUG BasicTypeRegistry:147 - Adding type registration character -> org.hibernate.type.CharacterType@3e86d0
14:31:39,044 DEBUG BasicTypeRegistry:147 - Adding type registration char -> org.hibernate.type.CharacterType@3e86d0
14:31:39,045 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Character -> org.hibernate.type.CharacterType@3e86d0
14:31:39,048 DEBUG BasicTypeRegistry:147 - Adding type registration short -> org.hibernate.type.ShortType@9fef6f
14:31:39,048 DEBUG BasicTypeRegistry:147 - Adding type registration short -> org.hibernate.type.ShortType@9fef6f
14:31:39,048 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Short -> org.hibernate.type.ShortType@9fef6f
14:31:39,050 DEBUG BasicTypeRegistry:147 - Adding type registration integer -> org.hibernate.type.IntegerType@17172ea
14:31:39,052 DEBUG BasicTypeRegistry:147 - Adding type registration int -> org.hibernate.type.IntegerType@17172ea
14:31:39,052 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Integer -> org.hibernate.type.IntegerType@17172ea
14:31:39,055 DEBUG BasicTypeRegistry:147 - Adding type registration long -> org.hibernate.type.LongType@e39a3e
14:31:39,056 DEBUG BasicTypeRegistry:147 - Adding type registration long -> org.hibernate.type.LongType@e39a3e
14:31:39,056 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Long -> org.hibernate.type.LongType@e39a3e
14:31:39,058 DEBUG BasicTypeRegistry:147 - Adding type registration float -> org.hibernate.type.FloatType@1858610
14:31:39,059 DEBUG BasicTypeRegistry:147 - Adding type registration float -> org.hibernate.type.FloatType@1858610
14:31:39,059 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Float -> org.hibernate.type.FloatType@1858610
14:31:39,061 DEBUG BasicTypeRegistry:147 - Adding type registration double -> org.hibernate.type.DoubleType@1a125f0
14:31:39,061 DEBUG BasicTypeRegistry:147 - Adding type registration double -> org.hibernate.type.DoubleType@1a125f0
14:31:39,061 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Double -> org.hibernate.type.DoubleType@1a125f0
14:31:39,064 DEBUG BasicTypeRegistry:147 - Adding type registration big_decimal -> org.hibernate.type.BigDecimalType@197d257
14:31:39,064 DEBUG BasicTypeRegistry:147 - Adding type registration java.math.BigDecimal -> org.hibernate.type.BigDecimalType@197d257
14:31:39,066 DEBUG BasicTypeRegistry:147 - Adding type registration big_integer -> org.hibernate.type.BigIntegerType@108786b
14:31:39,066 DEBUG BasicTypeRegistry:147 - Adding type registration java.math.BigInteger -> org.hibernate.type.BigIntegerType@108786b
14:31:39,068 DEBUG BasicTypeRegistry:147 - Adding type registration string -> org.hibernate.type.StringType@eee36c
14:31:39,068 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.String -> org.hibernate.type.StringType@eee36c
14:31:39,069 DEBUG BasicTypeRegistry:147 - Adding type registration url -> org.hibernate.type.UrlType@f5da06
14:31:39,070 DEBUG BasicTypeRegistry:147 - Adding type registration java.net.URL -> org.hibernate.type.UrlType@f5da06
14:31:39,073 DEBUG BasicTypeRegistry:147 - Adding type registration date -> org.hibernate.type.DateType@1ac04e8
14:31:39,073 DEBUG BasicTypeRegistry:147 - Adding type registration java.sql.Date -> org.hibernate.type.DateType@1ac04e8
14:31:39,075 DEBUG BasicTypeRegistry:147 - Adding type registration time -> org.hibernate.type.TimeType@a18aa2
14:31:39,076 DEBUG BasicTypeRegistry:147 - Adding type registration java.sql.Time -> org.hibernate.type.TimeType@a18aa2
14:31:39,078 DEBUG BasicTypeRegistry:147 - Adding type registration timestamp -> org.hibernate.type.TimestampType@14fe5c
14:31:39,078 DEBUG BasicTypeRegistry:147 - Adding type registration java.sql.Timestamp -> org.hibernate.type.TimestampType@14fe5c
14:31:39,078 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.Date -> org.hibernate.type.TimestampType@14fe5c
14:31:39,080 DEBUG BasicTypeRegistry:147 - Adding type registration dbtimestamp -> org.hibernate.type.DbTimestampType@1a7bf11
14:31:39,081 DEBUG BasicTypeRegistry:147 - Adding type registration calendar -> org.hibernate.type.CalendarType@fabe9
14:31:39,082 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.Calendar -> org.hibernate.type.CalendarType@fabe9
14:31:39,082 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.GregorianCalendar -> org.hibernate.type.CalendarType@fabe9
14:31:39,083 DEBUG BasicTypeRegistry:147 - Adding type registration calendar_date -> org.hibernate.type.CalendarDateType@601bb1
14:31:39,088 DEBUG BasicTypeRegistry:147 - Adding type registration locale -> org.hibernate.type.LocaleType@13f5d07
14:31:39,088 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.Locale -> org.hibernate.type.LocaleType@13f5d07
14:31:39,090 DEBUG BasicTypeRegistry:147 - Adding type registration currency -> org.hibernate.type.CurrencyType@1a16869
14:31:39,090 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.Currency -> org.hibernate.type.CurrencyType@1a16869
14:31:39,091 DEBUG BasicTypeRegistry:147 - Adding type registration timezone -> org.hibernate.type.TimeZoneType@18d107f
14:31:39,091 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.TimeZone -> org.hibernate.type.TimeZoneType@18d107f
14:31:39,092 DEBUG BasicTypeRegistry:147 - Adding type registration class -> org.hibernate.type.ClassType@1372a1a
14:31:39,093 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Class -> org.hibernate.type.ClassType@1372a1a
14:31:39,095 DEBUG BasicTypeRegistry:147 - Adding type registration uuid-binary -> org.hibernate.type.UUIDBinaryType@1c78e57
14:31:39,095 DEBUG BasicTypeRegistry:147 - Adding type registration java.util.UUID -> org.hibernate.type.UUIDBinaryType@1c78e57
14:31:39,096 DEBUG BasicTypeRegistry:147 - Adding type registration uuid-char -> org.hibernate.type.UUIDCharType@f6a746
14:31:39,097 DEBUG BasicTypeRegistry:147 - Adding type registration pg-uuid -> org.hibernate.type.PostgresUUIDType@1e63e3d
14:31:39,099 DEBUG BasicTypeRegistry:147 - Adding type registration binary -> org.hibernate.type.BinaryType@18fe7c3
14:31:39,099 DEBUG BasicTypeRegistry:147 - Adding type registration byte[] -> org.hibernate.type.BinaryType@18fe7c3
14:31:39,099 DEBUG BasicTypeRegistry:147 - Adding type registration [B -> org.hibernate.type.BinaryType@18fe7c3
14:31:39,100 DEBUG BasicTypeRegistry:147 - Adding type registration wrapper-binary -> org.hibernate.type.WrapperBinaryType@1be2d65
14:31:39,101 DEBUG BasicTypeRegistry:147 - Adding type registration Byte[] -> org.hibernate.type.WrapperBinaryType@1be2d65
14:31:39,101 DEBUG BasicTypeRegistry:147 - Adding type registration [Ljava.lang.Byte; -> org.hibernate.type.WrapperBinaryType@1be2d65
14:31:39,102 DEBUG BasicTypeRegistry:147 - Adding type registration image -> org.hibernate.type.ImageType@1172e08
14:31:39,103 DEBUG BasicTypeRegistry:147 - Adding type registration characters -> org.hibernate.type.CharArrayType@6eb38a
14:31:39,103 DEBUG BasicTypeRegistry:147 - Adding type registration char[] -> org.hibernate.type.CharArrayType@6eb38a
14:31:39,103 DEBUG BasicTypeRegistry:147 - Adding type registration [C -> org.hibernate.type.CharArrayType@6eb38a
14:31:39,105 DEBUG BasicTypeRegistry:147 - Adding type registration wrapper-characters -> org.hibernate.type.CharacterArrayType@1eed786
14:31:39,105 DEBUG BasicTypeRegistry:147 - Adding type registration [Ljava.lang.Character; -> org.hibernate.type.CharacterArrayType@1eed786
14:31:39,106 DEBUG BasicTypeRegistry:147 - Adding type registration Character[] -> org.hibernate.type.CharacterArrayType@1eed786
14:31:39,107 DEBUG BasicTypeRegistry:147 - Adding type registration text -> org.hibernate.type.TextType@12dacd1
14:31:39,116 DEBUG BasicTypeRegistry:147 - Adding type registration blob -> org.hibernate.type.BlobType@1888759
14:31:39,116 DEBUG BasicTypeRegistry:147 - Adding type registration java.sql.Blob -> org.hibernate.type.BlobType@1888759
14:31:39,116 DEBUG BasicTypeRegistry:147 - Adding type registration materialized_blob -> org.hibernate.type.MaterializedBlobType@e53108
14:31:39,117 DEBUG BasicTypeRegistry:147 - Adding type registration wrapper_materialized_blob -> org.hibernate.type.WrappedMaterializedBlobType@19189e1
14:31:39,123 DEBUG BasicTypeRegistry:147 - Adding type registration clob -> org.hibernate.type.ClobType@1d5550d
14:31:39,123 DEBUG BasicTypeRegistry:147 - Adding type registration java.sql.Clob -> org.hibernate.type.ClobType@1d5550d
14:31:39,124 DEBUG BasicTypeRegistry:147 - Adding type registration materialized_clob -> org.hibernate.type.MaterializedClobType@a0dcd9
14:31:39,124 DEBUG BasicTypeRegistry:147 - Adding type registration wrapper_characters_clob -> org.hibernate.type.CharacterArrayClobType@15f5897
14:31:39,125 DEBUG BasicTypeRegistry:147 - Adding type registration characters_clob -> org.hibernate.type.PrimitiveCharacterArrayClobType@1cfb549
14:31:39,127 DEBUG BasicTypeRegistry:147 - Adding type registration serializable -> org.hibernate.type.SerializableType@1820dda
14:31:39,130 DEBUG BasicTypeRegistry:147 - Adding type registration object -> org.hibernate.type.ObjectType@b89838
14:31:39,131 DEBUG BasicTypeRegistry:147 - Adding type registration java.lang.Object -> org.hibernate.type.ObjectType@b89838
14:31:39,131 DEBUG BasicTypeRegistry:147 - Adding type registration imm_date -> org.hibernate.type.AdaptedImmutableType@110b053
14:31:39,131 DEBUG BasicTypeRegistry:147 - Adding type registration imm_time -> org.hibernate.type.AdaptedImmutableType@a83b8a
14:31:39,132 DEBUG BasicTypeRegistry:147 - Adding type registration imm_timestamp -> org.hibernate.type.AdaptedImmutableType@dd20f6
14:31:39,132 DEBUG BasicTypeRegistry:147 - Adding type registration imm_dbtimestamp -> org.hibernate.type.AdaptedImmutableType@19efb05
14:31:39,132 DEBUG BasicTypeRegistry:147 - Adding type registration imm_calendar -> org.hibernate.type.AdaptedImmutableType@723d7c
14:31:39,132 DEBUG BasicTypeRegistry:147 - Adding type registration imm_calendar_date -> org.hibernate.type.AdaptedImmutableType@22c95b
14:31:39,132 DEBUG BasicTypeRegistry:147 - Adding type registration imm_binary -> org.hibernate.type.AdaptedImmutableType@1d1acd3
14:31:39,133 DEBUG BasicTypeRegistry:147 - Adding type registration imm_serializable -> org.hibernate.type.AdaptedImmutableType@a981ca
14:31:39,155 INFO Version:37 - Hibernate Commons Annotations 3.2.0.Final
14:31:39,165 INFO Environment:603 - Hibernate 3.6.4.Final
14:31:39,166 INFO Environment:636 - hibernate.properties not found
14:31:39,170 INFO Environment:814 - Bytecode provider name : javassist
14:31:39,173 INFO Environment:695 - using JDK 1.4 java.sql.Timestamp handling
14:31:39,238 INFO Configuration:2156 - configuring from resource: /hibernate.cfg.xml
14:31:39,238 INFO Configuration:2175 - Configuration resource: /hibernate.cfg.xml
14:31:39,285 WARN DTDEntityResolver:73 - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
14:31:39,310 INFO Configuration:2297 - Configured SessionFactory: null
14:31:39,325 INFO Dialect:135 - Using dialect: org.hibernate.dialect.FirebirdDialect
14:31:39,368 INFO Configuration:1676 - Hibernate Validator not found: ignoring
14:31:39,374 INFO SchemaExport:234 - Running hbm2ddl schema export
14:31:39,375 INFO SchemaExport:262 - exporting generated schema to database
14:31:39,378 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
14:31:39,378 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
14:31:39,378 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
14:31:39,385 INFO DriverManagerConnectionProvider:103 - using driver: org.firebirdsql.jdbc.FBDriver at URL: jdbc:firebirdsql:localhost/3050:D:\MEUBANCO.fdb
14:31:39,385 INFO DriverManagerConnectionProvider:109 - connection properties: {user=SYSDBA, password=****}
14:31:39,533 INFO SchemaExport:281 - schema export complete
14:31:39,535 INFO DriverManagerConnectionProvider:170 - cleaning up connection pool: jdbc:firebirdsql:localhost/3050:D:\MEUBANCO.fdb
Mais uma vez obrigado!