Boa noite pessoal,
Estou fazendo alguns testes com o Hibernate e estou encontrando uma dificuldade na hora do Hibernate criar a tabela a partir da minha classe.
Segue minha Classe Usuario
@Entity
@Table
public class Usuarios {
private static final long serialVersionUID = 1L;
@Id
@Column
private Integer id;
@Column(nullable=false,length=50)
private String nome;
@Column(nullable=false,length=6)
private String senha;
.... Getters e Setters... Equal e Hascode...
}
Minha Classe Main
public class Principal {
Public static void main(String[] args) {
SessionFactory sf = new AnnotationConfiguration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver")
.setProperty("hibernate.connection.url","jdbc:mysql://localhost:3306/test")
.setProperty("hibernate.connection.username", "root")
.setProperty("hibernate.connection.password", "senha")
.setProperty("hibernate.hbm2dll.auto","update")
.setProperty("hibernate.show_sql","false")
.setProperty("hibernate.format_sql","true")
.setProperty("hibernate.c3p0.acquire_incremente","1")
.setProperty("hibernate.c3p0.idle_test_period","100")
.setProperty("hibernate.c3p0.max_size","10")
.setProperty("hibernate.c3p0.max_statements","0")
.setProperty("hibernate.c3p0.min_size","5")
.setProperty("hibernate.c3p0.timeout","100")
.addAnnotatedClass(Usuarios.class)
.buildSessionFactory();
// Abre Sessão
Session session = sf.openSession();
session.beginTransaction();
// Persiste os Dados
Usuarios usr = new Usuarios();
usr.setId(1);
usr.setNome("Usuario1");
usr.setSenha("123");
session.save(usr);
// Fecha Sessão
session.beginTransaction().commit();
session.close();
sf.close();
}
}
Quando eu rodo da o seguinte erro. Ja procurei na net e nao achei nada… Me ajudem ai por favor…
Caused by: java.sql.BatchUpdateException: Table 'bd.usuarios' doesn't exist
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at Principal.main(Principal.java:43)