Create Tables with Hibernate [closed]

4

Good afternoon !!

I'm new to Hibernate and I've been trying for two days to implement table creation with it, I've already done several tutorials, but it does not work.

Can anyone help me?

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>

    <!-- Database connection settings -->
    <property name="connection.drive_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://127.0.0.1:3306/testebanco</property>
    <property name="connection.username">root</property>
    <property name="connection.password">102030</property>

    <!-- JDBC connection pool(use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache -->
    <property     name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

    <!-- Mapeamento das entidades -->
    <mapping class="teste.DAO.Estado" />

</session-factory>

Session creation class:

 public class HibernateUtil {
 private static SessionFactory sf = createSessionFactory();

public static SessionFactory getSf() {
    return sf;
}

private static SessionFactory createSessionFactory(){
    try{
        Configuration cfg = new Configuration().configure();

        ServiceRegistry registro = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();

        SessionFactory f = cfg.buildSessionFactory(registro);

        return f;
    }catch(Throwable ex){
        System.err.println("Erro ao criar a sessão " + ex);
        throw new ExceptionInInitializerError(ex);
    }

}
}

I'm using JUnit to run the tests:

public class HibernateUtilTeste {

@Test
public void conectar(){
    Session sessao =  HibernateUtil.getSf().openSession();
    sessao.close();
    HibernateUtil.getSf().close();
}
}

Class status:

@Entity
 @Table
 public class Estado extends GenericID {

private String nome;
private String sigla;

public String getNome() {
    return nome;
}
public void setNome(String nome) {
    this.nome = nome;
}
public String getSigla() {
    return sigla;
}
public void setSigla(String sigla) {
    this.sigla = sigla;
}

Class ID

 @SuppressWarnings("serial")
  @MappedSuperclass
 public class GenericID implements Serializable {

 @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}   
}

Log :

  

Log ---------       Jul 09, 2016 2:04:51 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.1.Final} Jul 09, 2016 2:04:51 PM   INFO: HHH000206: org.hibernate.cfg.Environment:   hibernate.properties not found Jul 09, 2016 2:04:51 PM   INFO: HHH000021: BuildBytecodeProvider org.hibernate.cfg.Environment:   Bytecode provider name: javassist Jul 09, 2016 2:04:51 PM   org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver   WARN resolverEntity: HHH90000012: Recognized obsolete hibernate   namespace link .   Use namespace link   instead. Support for obsolete DTD / XSD namespaces may be removed at   any time. Jul 09, 2016 2:04:51 PM   org.hibernate.annotations.common.reflection.java.JavaReflectionManager    INFO: HCANN000001: Hibernate Commons Annotations   {5.0.1.Final} Jul 09, 2016 2:04:51 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   configure WARN: HHH10001002: Using Hibernate built-in connection pool   (not for production use!) Jul 09, 2016 2:04:51 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   INFO: HHH10001005: using driver [null] at URL   [jdbc: mysql: //127.0.0.1: 3306 / testbank] Jul 09, 2016 2:04:51 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   buildCreator INFO: HHH10001001: Connection properties: {user = root,   drive_class = com.mysql.jdbc.Driver, password = ****} Jul 09, 2016 2:04:51   PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   INFO: BuildCreator: HHH10001003: Autocommit mode: false Jul 09, 2016   2:04:51 PM   org.hibernate.engine.jdbc.connections.internal.PooledConnections    INFO: HHH000115: Hibernate connection pool size: 1 (min = 1) Sat   Jul 09 14:04:52 BRT 2016 WARN: Establishing SSL connection without   server's identity verification is not recommended. According to MySQL   5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option is not set. For compliance   with existing applications not using SSL the verifyServerCertificate   property is set to 'false'. You need either to explicitly disable SSL   by setting useSSL = false, or set useSSL = true and provide truststore for   server certificate verification. Jul 09, 2016 2:04:52 PM   INFO: HHH000400: Using dialect: org.hibernate.dialect.Dialect:   org.hibernate.dialect.MySQL5InnoDBDialect Jul 09, 2016 2:04:52 PM   org.hibernate.tool.schema.internal.SchemaCreatorImpl   INFO: HIH000476: ApplyImportSources: Executing import script   'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@45385f75'   Jul 09, 2016 2:04:53 PM   org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl   stop INFO: HHH10001008: Cleaning up connection pool   [jdbc: mysql: //127.0.0.1: 3306 / testbank]

    
asked by anonymous 09.07.2016 / 17:54

0 answers