pgtpgt 13 de set. de 2011
Que mensagem de erro? envie pra podermos ajudar…
Envie também o hibernate.cfg.xml ou persistence.xml… As opções para criar o banco deve ser create.
create
Se já estiver criado
update
paulovcorrea 13 de set. de 2011
hibernate.properties
hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost/ordemcompra_db
hibernate.connection.username = root
hibernate.connection.password = pvc160
hibernate.show_sql = true
hibernate.format_sql = true
hibernate.hbm2ddl.auto = update
Error :
1 [ main ] INFO org . hibernate . cfg . annotations . Version - Hibernate Annotations 3.4.0 . GA
14 [ main ] INFO org . hibernate . cfg . Environment - Hibernate 3.3.0 . SP1
20 [ main ] INFO org . hibernate . cfg . Environment - loaded properties from resource hibernate . properties : { hibernate . connection . driver_class = com . mysql . jdbc . Driver , hibernate . dialect = org . hibernate . dialect . MySQLInnoDBDialect , hibernate . format_sql = true , hibernate . connection . username = root , hibernate . hbm2ddl . auto = update , hibernate . connection . url = jdbc : mysql : // localhost / ordemcompra_db , hibernate . bytecode . use_reflection_optimizer = false , hibernate . show_sql = true , hibernate . connection . password =**** }
22 [ main ] INFO org . hibernate . cfg . Environment - Bytecode provider name : javassist
26 [ main ] INFO org . hibernate . cfg . Environment - using JDK 1.4 java . sql . Timestamp handling
76 [ main ] INFO org . hibernate . annotations . common . Version - Hibernate Commons Annotations 3.1.0 . GA
100 [ main ] INFO org . hibernate . cfg . search . HibernateSearchEventListenerRegister - Unable to find org . hibernate . search . event . FullTextIndexEventListener on the classpath . Hibernate Search is not enabled .
146 [ main ] INFO org . hibernate . cfg . AnnotationBinder - Binding entity from annotated class : br . com . sisordcompra . model . Produto
178 [ main ] INFO org . hibernate . cfg . annotations . EntityBinder - Bind entity br . com . sisordcompra . model . Produto on table Produto
211 [ main ] INFO org . hibernate . cfg . AnnotationBinder - Binding entity from annotated class : br . com . sisordcompra . model . Fornecedor
212 [ main ] INFO org . hibernate . cfg . annotations . EntityBinder - Bind entity br . com . sisordcompra . model . Fornecedor on table Fornecedor
214 [ main ] INFO org . hibernate . cfg . AnnotationBinder - Binding entity from annotated class : br . com . sisordcompra . model . OrdemCompra
214 [ main ] INFO org . hibernate . cfg . annotations . EntityBinder - Bind entity br . com . sisordcompra . model . OrdemCompra on table OrdemCompra
249 [ main ] INFO org . hibernate . cfg . AnnotationBinder - Binding entity from annotated class : br . com . sisordcompra . model . Item
249 [ main ] INFO org . hibernate . cfg . annotations . EntityBinder - Bind entity br . com . sisordcompra . model . Item on table item
299 [ main ] INFO org . hibernate . cfg . annotations . CollectionBinder - Mapping collection : br . com . sisordcompra . model . OrdemCompra . listaItens -> item
302 [ main ] INFO org . hibernate . cfg . AnnotationConfiguration - Hibernate Validator not found : ignoring
Exception in thread "main" java . lang . ExceptionInInitializerError
at br . com . sisordcompra . dao . ProdutoDAO . < init > ( ProdutoDAO . java : 16 )
at br . com . sisordcompra . controle . ProdutoController . < clinit > ( ProdutoController . java : 10 )
at br . com . sisordcompra . teste . AdicionarProduto . main ( AdicionarProduto . java : 22 )
Caused by : org . hibernate . MappingException : Could not determine type for : br . com . sisordcompra . model . OrdemCompra , at table : item , for columns : [ org.hibernate.mapping.Column(compra) ]
at org . hibernate . mapping . SimpleValue . getType ( SimpleValue . java : 292 )
at org . hibernate . mapping . SimpleValue . isValid ( SimpleValue . java : 276 )
at org . hibernate . mapping . RootClass . validate ( RootClass . java : 216 )
at org . hibernate . cfg . Configuration . validate ( Configuration . java : 1135 )
at org . hibernate . cfg . Configuration . buildSessionFactory ( Configuration . java : 1320 )
at org . hibernate . cfg . AnnotationConfiguration . buildSessionFactory ( AnnotationConfiguration . java : 867 )
at br . com . sisordcompra . util . HibernateUtil . < clinit > ( HibernateUtil . java : 23 )
... 3 more
pgtpgt 13 de set. de 2011
Cara, na classe Item, você tem duas anotações @Id … Id determina a chave primária da sua tabela. Nesse caso você está criando duas chaves primárias em uma tabela… Deixe somente um atributo como @Id .
paulovcorrea 13 de set. de 2011
Bom o error não esta ai , eu deixando os dois como @id ou so um com o @id , da o mesmo erro , mas caso eu tire os @id dos dois me volta o erro :
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: br.com.sisordcompra.model.Item
meu erro acho q está nas declrações de @ManytoOne , no List … :S
Ev3rton 13 de set. de 2011
Olá,
Dê uma olhada neste link para visualizar alguns exemplos de como implementar um relacionamento N-N com anotações:
http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns
[ ]'s