Boa noite pessoal
estou estudando Hibernate e ao tentar criar uma tabela no banco a partir do Hibernate esta dando essa mensagem,
alguma idéia de como resolver isso?
[code]17:28:55,526 INFO Version:15 - Hibernate Annotations 3.4.0.GA
17:28:55,554 INFO Environment:543 - Hibernate 3.3.1.GA
17:28:55,571 INFO Environment:576 - hibernate.properties not found
17:28:55,578 INFO Environment:709 - Bytecode provider name : javassist
17:28:55,587 INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
17:28:55,707 INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA
17:28:55,712 INFO Configuration:1460 - configuring from resource: /hibernate.cfg.xml
17:28:55,713 INFO Configuration:1437 - Configuration resource: /hibernate.cfg.xml
17:28:55,895 INFO Configuration:1575 - Configured SessionFactory: null
17:28:55,924 INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
17:28:56,137 INFO AnnotationBinder:419 - Binding entity from annotated class: br.com.estudos.modelo.Pessoa
17:28:56,210 INFO EntityBinder:422 - Bind entity br.com.estudos.modelo.Pessoa on table pessoa
17:28:56,329 INFO AnnotationConfiguration:369 - Hibernate Validator not found: ignoring
17:28:56,422 INFO SchemaExport:226 - Running hbm2ddl schema export
17:28:56,423 INFO SchemaExport:251 - exporting generated schema to database
17:28:56,427 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
17:28:56,428 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
17:28:56,428 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
17:28:56,443 INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/jsf
17:28:56,444 INFO DriverManagerConnectionProvider:109 - connection properties: {user=root, password=****}
17:28:56,673 ERROR SchemaExport:274 - schema export unsuccessful
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:252)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
at br.com.estudos.util.GerarTabelas.main(GerarTabelas.java:13)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.(Socket.java:372)
at java.net.Socket.(Socket.java:215)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:280)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
… 16 more
[/code]
Obrigado
Ola,
Como voce esta mapeando sua classe para a criacao da tabela : por annotations ou por xml ?
Se possivel poste o codigo que mostre esse mapeamento e se for por xml alem do hbm.xml e da classe poste o hibernate.cfg.xml para que posse ser avaliado.
Flw.
Oi Daniel,
estou usando annotations
class Pessoa.java
[code]
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name=“pessoa”)
public class Pessoa implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="pessoa_id")
private Long id;
@Column(name="nome")
private String nome;
@Column(name="email")
private String email;
@Column(name="senha")
private String senha;
@Column(name="cpf")
private String cpf;
@Temporal(TemporalType.DATE)
@Column(name="data_nasc")
private Date dataNascimento;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public Date getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}[/code]
hibernate.cfg.xml
<?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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/jsf</property>
<property name="hibernate.connection.username">usuario</property>
<property name="hibernate.connection.password">senha</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">100</property>
<mapping class="br.com.estudos.model.Pessoa"/>
</session-factory>
</hibernate-configuration>
Ola,
Aparentemente parece tudo certo com seu codigo, mas quero saber umas coisas :
1 - Voce ja tentou trocar o dialeto que esta usando no XML para :
Se nao, teste isso mude o dialeto e tente rodar novamente.
2 - Outra coisa se no console ele gerar algum sql de criacao da tabela , teste o sql diretamente no banco e veja se funciona tambem.
E eu to vendo ali no erro que ele falhou bem na hora de fazer o Export do Schema se der poste a classe onde voce esta fazendo o SchemaExport pra que possa dar uma olhada, se ta tudo certo tambem.
Da uma olhada aqui tambem se nao resolver : http://www.guj.com.br/posts/list/93993.java
quem sabe ajude.
Flw.
Daniel,
o link que você passou não ajudou muito. 
troquei o dialeto e continua com o mesmo problema.
class GerarTabelas
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class GerarTabelas {
public static void main(String[] args) {
Configuration cfg = new AnnotationConfiguration();
cfg.configure();
SchemaExport se = new SchemaExport(cfg);
se.create(true, true);
}
}
Ola,
Seu código aparetemente está certo, mas vejo no erro que todo o problema está relacionado com que sua aplicação não está conseguindo se comunicar com o banco.
Por isso te pergunto, o seu banco está rodando normalmente (digo sozinho) ?, o schema em seu banco já existe?
Pois o Hibernate só criará as tabelas pra voce e nao o Schema do banco.
Veja o erro está justamente nessa linha :
17:28:56,673 ERROR SchemaExport:274 - schema export unsuccessful
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Eu encontrei um forum onde o pessoal solucionou este problema, de uma olhada :
http://forums.netbeans.org/post-14735.html
Flw.
Daniel,
o banco funciona normal, consigo acessar ele pelo mysql query browser e pelo administrator. O shema eu criei vazio, justamente para o Hibernate criar as tabelas.
Li os links que voce me mandou e eles falavam para comentar a opção skip-network da inicialização do mysql, foi o que eu fiz e agora a mensagem
da exceção mudou:
13:02:57,496 INFO Version:15 - Hibernate Annotations 3.4.0.GA
13:02:57,595 INFO Environment:543 - Hibernate 3.3.1.GA
13:02:57,620 INFO Environment:576 - hibernate.properties not found
13:02:57,626 INFO Environment:709 - Bytecode provider name : javassist
13:02:57,635 INFO Environment:627 - using JDK 1.4 java.sql.Timestamp handling
13:02:57,826 INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA
13:02:57,834 INFO Configuration:1460 - configuring from resource: /hibernate.cfg.xml
13:02:57,836 INFO Configuration:1437 - Configuration resource: /hibernate.cfg.xml
13:02:58,074 INFO Configuration:1575 - Configured SessionFactory: null
13:02:58,103 INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
13:02:58,514 INFO AnnotationBinder:419 - Binding entity from annotated class: br.com.serjaum.modelo.Pessoa
13:02:58,589 INFO EntityBinder:422 - Bind entity br.com.serjaum.modelo.Pessoa on table pessoa
13:02:58,711 INFO AnnotationConfiguration:369 - Hibernate Validator not found: ignoring
13:02:58,880 INFO SchemaExport:226 - Running hbm2ddl schema export
13:02:58,881 INFO SchemaExport:251 - exporting generated schema to database
13:02:58,896 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
13:02:58,896 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20
13:02:58,896 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
13:02:58,967 INFO DriverManagerConnectionProvider:103 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/jsf
13:02:58,967 INFO DriverManagerConnectionProvider:109 - connection properties: {user=root, password=****}
13:02:59,340 ERROR SchemaExport:274 - schema export unsuccessful
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:252)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
at br.com.serjaum.util.GerarTabelas.main(GerarTabelas.java:13)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 1 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:666)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1069)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
... 16 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:590)
... 18 more
ninguem passou por isso que possa me ajudar? :?:
Você tá usando MySQL, né? O banco tá criado? Se tiver, digita mysqld --console e tenta devolta.
Fiz o que você falou mas continua dando o mesmo erro.
[root@linux gregory]# /etc/rc.d/mysqld --console
usage: /etc/rc.d/mysqld {start|stop|restart}
[root@linux gregory]# mysqld --console
090916 12:17:37 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
090916 12:17:37 [ERROR] Aborting
090916 12:17:37 [Note] mysqld: Shutdown complete
Na verdade, isso é erro de que você não tem permissão. Você tem a senha de root da máquina aí?
Mostra os bancos que você tem criado.
Fala André,
Tenho a senha de root sim, segue um print com os bancos
http://imagebin.ca/view/ph2P2n8i.html
Opa, cheguei meio tarde, mas não dá nada. Você tem isso:
Né? Mas você não tem o banco chamado ‘jsf’ criado.