Jhonny2 0 Denunciar post Postado Março 28, 2013 Olá, eu estou fazendo java hibernate como provedor de persistência e está dando erro e não sei o que é. Tenho a classe Estado e Cidade, preciso fazer o relacionamento delas. Classe Estado @Entity public class Estado implements Serializable { @Id @SequenceGenerator(name="SEQ", allocationSize=1,sequenceName= "GEN_ID_ESTADO") @GeneratedValue(generator="SEQ",strategy= GenerationType.SEQUENCE) private Integer id; @Column(length=50, nullable= false, unique= true) private String nome; public Estado() { } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } @Override public String toString() { return nome; } } Classe Cidade @Entity public class Cidade implements Serializable { @Id @SequenceGenerator(name="SEQ", allocationSize=1,sequenceName= "GEN_ID_CIDADE") @GeneratedValue(generator="SEQ",strategy= GenerationType.SEQUENCE) private Integer id; @Column(length=50, nullable= false) private String nome; @ManyToOne private Estado estado; public Cidade() { } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } public Estado getEstado() { return estado; } public void setEstado(Estado estado) { this.estado = estado; } @Override public String toString() { return nome; } } E tenho a classe teste, que é para executar public class Teste { public static void main(String[] args) { Estado e = new Estado(); e.setNome("Rio Grande do Sul"); Cidade c = new Cidade(); c.setNome("Porto Alegre"); c.setEstado(e); EntityManagerFactory emf; emf = Persistence.createEntityManagerFactory("EstoqueModelPU"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); em.persist(e); em.getTransaction().commit(); em.close(); EntityManagerFactory emf1; emf1 = Persistence.createEntityManagerFactory("EstoqueModelPU"); EntityManager em1 = emf1.createEntityManager(); em1.getTransaction().begin(); em1.persist(c); em1.getTransaction().commit(); em1.close(); } } E por fim o erro =/ O que fazer? Não cria as tabelas no postgre run: Mar 28, 2013 10:35:12 AM org.hibernate.cfg.annotations.Version <clinit> INFO: Hibernate Annotations 3.3.1.GA Mar 28, 2013 10:35:12 AM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.5 Mar 28, 2013 10:35:12 AM org.hibernate.cfg.Environment <clinit> INFO: hibernate.properties not found Mar 28, 2013 10:35:12 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: Bytecode provider name : cglib Mar 28, 2013 10:35:12 AM org.hibernate.cfg.Environment <clinit> INFO: using JDK 1.4 java.sql.Timestamp handling Mar 28, 2013 10:35:12 AM org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.3.2.GA Mar 28, 2013 10:35:13 AM org.hibernate.cfg.AnnotationBinder bindClass INFO: Binding entity from annotated class: br.upf.ads.daoo.estoque.beans.Grupo Mar 28, 2013 10:35:13 AM org.hibernate.cfg.annotations.EntityBinder bindTable INFO: Bind entity br.upf.ads.daoo.estoque.beans.Grupo on table Grupo Mar 28, 2013 10:35:13 AM org.hibernate.cfg.AnnotationBinder bindClass INFO: Binding entity from annotated class: br.upf.ads.daoo.estoque.beans.Estado Mar 28, 2013 10:35:13 AM org.hibernate.cfg.annotations.EntityBinder bindTable INFO: Bind entity br.upf.ads.daoo.estoque.beans.Estado on table Estado Mar 28, 2013 10:35:13 AM org.hibernate.cfg.AnnotationBinder bindClass INFO: Binding entity from annotated class: br.upf.ads.daoo.estoque.beans.Cidade Mar 28, 2013 10:35:13 AM org.hibernate.cfg.annotations.EntityBinder bindTable INFO: Bind entity br.upf.ads.daoo.estoque.beans.Cidade on table Cidade Mar 28, 2013 10:35:13 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile INFO: Hibernate Validator not found: ignoring Mar 28, 2013 10:35:13 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Using Hibernate built-in connection pool (not for production use!) Mar 28, 2013 10:35:13 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Hibernate connection pool size: 20 Mar 28, 2013 10:35:13 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: autocommit mode: true Mar 28, 2013 10:35:13 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/estoquedb Mar 28, 2013 10:35:13 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: connection properties: {user=estoque, password=****, autocommit=true, release_mode=auto} Mar 28, 2013 10:35:13 AM org.hibernate.cfg.SettingsFactory buildSettings WARNING: Could not obtain connection metadata org.postgresql.util.PSQLException: FATAL: autentica��o do tipo password falhou para usu�rio "estoque" at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:293) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22) at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:32) at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) at java.sql.DriverManager.getConnection(DriverManager.java:579) at java.sql.DriverManager.getConnection(DriverManager.java:190) at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33) at br.upf.ads.daoo.estoque.testes.Teste.main(Teste.java:39) Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: EstoqueModelPU] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33) at br.upf.ads.daoo.estoque.testes.Teste.main(Teste.java:39) Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57) at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39) at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669) ... 4 more Java Result: 1 CONSTRUÍDO COM SUCESSO (tempo total: 3 segundos) Compartilhar este post Link para o post Compartilhar em outros sites
Vergil 15 Denunciar post Postado Março 30, 2013 Pela pilha de erros tudo indica que foi falha na autenticação no acesso ao banco de dados. Você terá que consertar as propriedades de conexão no seu persistence.xml pra resolver isso. Este link pode ajudá-lo http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/configuration.html Compartilhar este post Link para o post Compartilhar em outros sites
diogosouza 0 Denunciar post Postado Abril 5, 2013 Acho que nesse caso o erro tá mais relacionado à senha dele mesmo... Muda a senha nas configurações e pronto.. :-) Compartilhar este post Link para o post Compartilhar em outros sites