Solucionado (ver solução)
Solucionado
(ver solução)
22
respostas

Spring-Boot com JPA nao gera as tabelas do banco

Boa noite,

O meu projeto Spring-Boot nao consegue gerar as tabelas do banco, diferentemente de quando estava usando Hibernate com Tomcat ou Wildfly e o persistente.xml

Tem alguma outra dependência que tenha que usar? Tenho que criar alguma configuração programaticamente?

Atenciosamente, Bernardo

Dependencias

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>

Classe Pessoa

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.GenericGenerator;

@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Pessoa implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;

    private String nome;

    private String email;

    public Pessoa() {

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = 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;
    }
}

JPA application.propeerties

spring.jpa.hibernate.ddl-auto: update
spring.jpa.show-sql: true
spring.jpa.generate-ddl: true

Datasource application.propeerties

spring.datasource.driver-class-name: com.mysql.jdbc.Driver
spring.datasource.username: 
spring.datasource.password: 
spring.datasource.url: jdbc:mysql://localhost:3306/Teste
22 respostas

Oi Bernado,

A única coisa que precisa fazer é adicionar as propriedades no arquivo application.properties.

Confere se essas propriedades estão declaradas no seu arquivo, e se as informações estão corretas:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/Teste
spring.datasource.username=root
spring.datasource.password=

spring.jpa.hibernate.ddl-auto=update

Confere em especial o username e o password do banco de dados.

Outra coisa, o hibernate apenas cria as tabelas, mas não o Banco de Dados em si. Verifique no MySQL se você já tem esse database Teste criado.

Dá para configurar a criação automática do database, caso ele não exista, alterando essa propriedade:

spring.datasource.url=jdbc:mysql://localhost/Teste?createDatabaseIfNotExist=true

Bons estudos!

Olá Rodrigo, adicionei a propriedade de criação de banco como indicado, mas o problema persiste

Datasource Configuration

spring.datasource.driver-class-name: com.mysql.jdbc.Driver
spring.datasource.url: jdbc:mysql://localhost:3306/Teste?createDatabaseIfNotExist=true
spring.datasource.username: root
spring.datasource.password:

JPA configuration

spring.jpa.hibernate.ddl-auto: update
spring.jpa.show-sql: true

Saída console

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.0.RELEASE)

2018-03-23 11:22:17.811  INFO 72087 --- [  restartedMain] br.com.easyfood.start.AppInit            : Starting AppInit on 145.155.EARLY-REGISTRATION.of.SURFnet.invalid with PID 72087 (/Users/belofeso/Downloads/EasyFood/target/classes started by belofeso in /Users/belofeso/Downloads/EasyFood)
2018-03-23 11:22:17.813  INFO 72087 --- [  restartedMain] br.com.easyfood.start.AppInit            : No active profile set, falling back to default profiles: default
2018-03-23 11:22:17.872  INFO 72087 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3f1d3e7d: startup date [Fri Mar 23 11:22:17 BRT 2018]; root of context hierarchy
2018-03-23 11:22:18.975  INFO 72087 --- [  restartedMain] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-03-23 11:22:19.090  INFO 72087 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a01dea41] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-23 11:22:19.120  INFO 72087 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.joinfaces.autoconfigure.javaxfaces.ProjectStageAutoConfiguration' of type [org.joinfaces.autoconfigure.javaxfaces.ProjectStageAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-23 11:22:19.482  INFO 72087 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-03-23 11:22:19.510  INFO 72087 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-03-23 11:22:19.510  INFO 72087 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-03-23 11:22:19.518  INFO 72087 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/belofeso/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-03-23 11:22:19.849  INFO 72087 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2018-03-23 11:22:19.861  INFO 72087 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-03-23 11:22:19.862  INFO 72087 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1992 ms
2018-03-23 11:22:20.053  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-03-23 11:22:20.056  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-23 11:22:20.056  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-23 11:22:20.057  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-23 11:22:20.057  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-03-23 11:22:20.057  INFO 72087 --- [ost-startStop-1] o.s.b.w.servlet.Filter

Boa tarde!

O Hibernate, que implementa o JPA, não gera banco de dados. Ele consegue gerar as tabelas, índices, relacinamentos, etc. Logo, você deve gerar o banco de dados que irá utilizar e logar com o usuário de banco de dados que tenha as permissões apropriadas para manipulação do mesmo banco de dados.

Abs.

Olá Rogério, me expressei mal ao escrever, são as tabelas mesmo, o Schema do banco está criado já, para que o Hibernate possa atuar, assim com ocorre ao usar wildfly e JTA e / ou persistence.xml e Tomcat, etc. O que está ocorrendo, é que o spring-boot não está gerando as tabelas e nem apresentando qualquer erro que justifique a falha.

Atenciosamente, Bernardo

Você poderia fazer um teste e inserir a seguinte classe:

// imports ...

@Entity
@Table(name="tb_aluno")
public class Aluno  implements Serializable {

    private static final long serialVersionUID = 1L;

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

    @Column(name="nome_razaosocial", length=100, nullable=false)
    private String nome;

// Gets e  Sets

e ver se a tabela tb_aluno será criada?

Uma coisa que percebi foi a não utilização da notação @Table no seu código.

Abs.

Continua sem criar, vou postar a classe aqui e a saída do console a seguir

Classe Aluno

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tb_aluno")
public class Aluno {

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

    @Column(name = "nome_razaoSocial", length = 100, nullable = false)
    private String nome;

    public Long getId() {
        return id;
    }

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

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
}

My Sql

mysql> use Teste;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql>

application.properties

spring.datasource.driver-class-name: com.mysql.jdbc.Driver
spring.datasource.url: jdbc:mysql://localhost:3306/Teste?createDatabaseIfNotExist=true
spring.datasource.username: root
spring.datasource.password: 
spring.jpa.hibernate.ddl-auto: update
spring.jpa.show-sql: true

Console

2018-03-24 21:22:05.353  INFO 30685 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-03-24 21:22:05.432  INFO 30685 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.14.Final}
2018-03-24 21:22:05.433  INFO 30685 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-03-24 21:22:05.468  INFO 30685 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-03-24 21:22:05.564  INFO 30685 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-24 21:22:05.791  INFO 30685 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-03-24 21:22:06.335  INFO 30685 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2ebcef9e: startup date [Sat Mar 24 21:22:00 BRT 2018]; root of context hierarchy
2018-03-24 21:22:06.414  INFO 30685 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-24 21:22:06.416  INFO 30685 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-24 21:22:06.458  INFO 30685 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:22:06.458  INFO 30685 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:22:06.501  INFO 30685 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:22:06.589  INFO 30685 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2018-03-24 21:22:06.657  INFO 30685 --- [  restartedMain] o.s.aop.framework.CglibAopProxy          : Method [java.util.Map javax.faces.component.UIComponentBase.getDescriptorMap()] is package-visible across different ClassLoaders and cannot get proxied via CGLIB: Declare this method as public or protected if you need to support invocations through the proxy.
2018-03-24 21:22:06.703  INFO 30685 --- [  restartedMain] o.s.aop.framework.CglibAopProxy          : Method [synchronized void org.joinfaces.autoconfigure.viewscope.SessionHelper.cleanup()] is package-visible across different ClassLoaders and cannot get proxied via CGLIB: Declare this method as public or protected if you need to support invocations through the proxy.
2018-03-24 21:22:06.941  INFO 30685 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-03-24 21:22:07.017  INFO 30685 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-24 21:22:07.018  INFO 30685 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-03-24 21:22:07.025  INFO 30685 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-03-24 21:22:07.077  INFO 30685 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-03-24 21:22:07.081  INFO 30685 --- [  restartedMain] br.com.easyfood.start.AppInit            : Started AppInit in 6.537 seconds (JVM running for 6.988)

A versão do Spring Boot que você está usando é a 2.0.0.XXX ? Se for, use o release anterior, e veja se funciona. Tive um problema quando tentei migrar para versão mais nova. Faça o teste!

Aguando uma resposta.

Use a seguinte versão:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath/> 
    </parent>

Eu já tinha esquecido que você realmente estava usando a versão 2.0.0.RELEASE.

v.1.5.10

Sem sucesso, apenas apresentou incompatibilidade com a dependência do join faces, mas o resultado permaneceu idêntico.

2018-03-24 21:57:22.069  INFO 33454 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-03-24 21:57:22.082  INFO 33454 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-03-24 21:57:22.214  INFO 33454 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2018-03-24 21:57:22.215  INFO 33454 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-03-24 21:57:22.216  INFO 33454 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2018-03-24 21:57:22.250  INFO 33454 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-03-24 21:57:22.349  INFO 33454 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-24 21:57:22.507  INFO 33454 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2018-03-24 21:57:22.545  INFO 33454 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-03-24 21:57:22.815  INFO 33454 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@208b35a0: startup date [Sat Mar 24 21:57:19 BRT 2018]; root of context hierarchy
2018-03-24 21:57:22.891  INFO 33454 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-24 21:57:22.892  INFO 33454 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-24 21:57:22.921  INFO 33454 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:57:22.921  INFO 33454 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:57:22.959  INFO 33454 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 21:57:23.475  INFO 33454 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-03-24 21:57:23.546  INFO 33454 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-24 21:57:23.613  INFO 33454 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-03-24 21:57:23.619  INFO 33454 --- [  restartedMain] br.com.easyfood.start.AppInit            : Started AppInit in 4.15 seconds (JVM running for 4.522)

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.teste</groupId>
    <artifactId>Teste</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Teste</name>
    <description>Teste  Project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- SpringBoot Starter -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- SpringBoot Starter Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- SpringBoot Starter Thymeleaf -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- JPA -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- JSF -->
    <!-- <dependency> <groupId>org.joinfaces</groupId> <artifactId>jsf-spring-boot-starter</artifactId> 
        <version>3.0.2</version> </dependency> -->

        <!-- PrimeFaces -->
    <!-- <dependency> <groupId>org.joinfaces</groupId> <artifactId>primefaces-spring-boot-starter</artifactId> 
        <version>3.0.2</version> </dependency> -->
        <!-- MySQL Connector/J -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Quando apresentou essa incompatibilidade o seu .jar permaneceu o mesmo dos fontes anteriores (sem alteração). Tente retirar essas dependência de sua aplicação só para fazer o teste em que estamos focando (banco de dados).

fiz o teste com a versões:

2.0.0
1.5.10 
1.5.8 
1.3.6

comentando o join faces como demonstrado no POM.xml acima, com a 1.5.8 e 1.3.6 a saída ainda indica um "schema update", mas que não ocorre na pratica. Vou postar a seguir a saída da 1.3.6 que foi a ultima que rodei agora.

2018-03-24 22:17:52.425  INFO 35062 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-03-24 22:17:52.432  INFO 35062 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-03-24 22:17:52.494  INFO 35062 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
2018-03-24 22:17:52.496  INFO 35062 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-03-24 22:17:52.497  INFO 35062 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2018-03-24 22:17:52.629  INFO 35062 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2018-03-24 22:17:52.984  INFO 35062 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-24 22:17:53.013  INFO 35062 --- [  restartedMain] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2018-03-24 22:17:53.078  INFO 35062 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2018-03-24 22:17:53.079  INFO 35062 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000102: Fetching database metadata
2018-03-24 22:17:53.080  INFO 35062 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000396: Updating schema
2018-03-24 22:17:53.080  INFO 35062 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000232: Schema update complete
2018-03-24 22:17:53.265  INFO 35062 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6feeac7a: startup date [Sat Mar 24 22:17:50 BRT 2018]; root of context hierarchy
2018-03-24 22:17:53.326  INFO 35062 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-24 22:17:53.327  INFO 35062 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-24 22:17:53.345  INFO 35062 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 22:17:53.345  INFO 35062 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 22:17:53.368  INFO 35062 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-24 22:17:53.764  INFO 35062 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-03-24 22:17:53.804  INFO 35062 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-24 22:17:53.865  INFO 35062 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-03-24 22:17:53.869  INFO 35062 --- [  restartedMain] br.com.easyfood.start.AppInit            : Started AppInit in 4.061 seconds (JVM running for 4.46)

Não use uma versão muito antiga. A versão que enviei certamente funciona. O problema está noutro lugar.

Veja se no arquivo principal de sua aplicação está parecido com este:


@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class PessoalApplication {

    public static void main(String[] args) {
        SpringApplication.run(PessoalApplication.class, args);
    }
}

Perceba as anotações na classe.

Desculpa a demora, fui gerar novamente o repositório do Maven, anteriormente tinha dado um problema na exibição do HTML e ao refazer o build da .m2 funcionou.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@EnableAutoConfiguration  // Adicionado agora
@ComponentScan //Adicionado agora
public class AppInit {

    public static void main(String[] args) {
        SpringApplication.run(AppInit.class, args);
    }
}

Mesmo adotando essas duas anotações nada mudou. com a versão 1.5.8 exibe o "schema update", mas não executa de fato.

Vamos tentar mais uma alteração. Em @ComponentScan você precisará colocar uma de suas classes que irá persistir, da seguinte forma:

@ComponentScan(basePackageClasses= {Aluno.class})

Isso informará ao Spring Boot para tomar conhecimento de todas as classes que estão no pacote em que a classe Aluno se encontra.

Como sua aplicação não apresenta erro, eu suponho que estas classes não estejam sendo reconhecidas pelo Spring. Caso você ache que outras classes que estejam noutros pacotes não estejam sendo encontradas pelo Spring, faça o mesmo para somente uma classe qualquer do pacote não reconhecido pelo Spring. Exemplo:

@ComponentScan(basePackageClasses= {Aluno.class, OutraClasseDeOutroPacote.class})

Veja que ao indicar a classe tempos que colocar ".class" (Aluno.class, OutraClasseDeOutroPacote.class, ...).

Abs.

Nada aconteceu.

classe AppInit

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import br.com.easyfood.modelo.pessoa.teste.Aluno;

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackageClasses = { Aluno.class })
public class AppInit {

    public static void main(String[] args) {
        SpringApplication.run(AppInit.class, args);
    }
}

My SQL

mysql> use Teste;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql>

v. 1.3.6.RELEASE

2018-03-25 10:32:19.055  INFO 92085 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-03-25 10:32:19.062  INFO 92085 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-03-25 10:32:19.122  INFO 92085 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
2018-03-25 10:32:19.124  INFO 92085 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-03-25 10:32:19.125  INFO 92085 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2018-03-25 10:32:19.307  INFO 92085 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2018-03-25 10:32:19.698  INFO 92085 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-25 10:32:19.729  INFO 92085 --- [  restartedMain] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2018-03-25 10:32:19.800  INFO 92085 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2018-03-25 10:32:19.800  INFO 92085 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000102: Fetching database metadata
2018-03-25 10:32:19.801  INFO 92085 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000396: Updating schema
2018-03-25 10:32:19.801  INFO 92085 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000232: Schema update complete
2018-03-25 10:32:20.004  INFO 92085 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@41aa08d3: startup date [Sun Mar 25 10:32:17 BRT 2018]; root of context hierarchy
2018-03-25 10:32:20.071  INFO 92085 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-25 10:32:20.071  INFO 92085 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-25 10:32:20.090  INFO 92085 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 10:32:20.090  INFO 92085 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 10:32:20.123  INFO 92085 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 10:32:20.549  INFO 92085 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-03-25 10:32:20.598  INFO 92085 --- [  restartedMain] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-25 10:32:20.674  INFO 92085 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-03-25 10:32:20.680  INFO 92085 --- [  restartedMain] br.com.easyfood.start.AppInit            : Started AppInit in 4.005 seconds (JVM running for 4.36)
solução!

Em seu pom.xml a dependência do conector MySql está assim:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>

altere ela para:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

Num de meus projetos essa especificação da versão do conector não ocorre. Parece ser padronizada também.

E use a versão 1.5.10 do Spring Boot. Neste essas coisas deveria funcionar. Quando você utiliza uma versão muito antiga do Spring Boot ele começa a utilizar um release do Hibernat anterior ao Java 8, então, 1.3.x já é muito antiga.

Uma outro sugestão é que você recrie o projeto na versão 1.5.10 e inicie pelas classes do domínio.

Gerei o projeto novamente com nome de teste 2 e agora gerou. Obrigado

v. 1.5.10.RELEASE

2018-03-25 12:48:39.070  INFO 3081 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-03-25 12:48:39.083  INFO 3081 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-03-25 12:48:39.136  INFO 3081 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2018-03-25 12:48:39.137  INFO 3081 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-03-25 12:48:39.139  INFO 3081 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2018-03-25 12:48:39.171  INFO 3081 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-03-25 12:48:39.253  INFO 3081 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-03-25 12:48:39.700  INFO 3081 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2018-03-25 12:48:39.713  INFO 3081 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: tb_aluno
2018-03-25 12:48:39.714  INFO 3081 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: tb_aluno
2018-03-25 12:48:39.785  INFO 3081 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-03-25 12:48:40.010  INFO 3081 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1445d7f: startup date [Sun Mar 25 12:48:37 BRT 2018]; root of context hierarchy
2018-03-25 12:48:40.078  INFO 3081 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-25 12:48:40.079  INFO 3081 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-25 12:48:40.100  INFO 3081 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 12:48:40.100  INFO 3081 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 12:48:40.139  INFO 3081 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-25 12:48:40.359  INFO 3081 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-25 12:48:40.433  INFO 3081 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-03-25 12:48:40.438  INFO 3081 --- [           main] br.com.teste.Teste2Application           : Started Teste2Application in 3.562 seconds (JVM running for 3.941)

Classe Aluno

package br.com.teste.modelo.pessoa;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tb_aluno")
public class Aluno {

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

    @Column(name = "nome_razaoSocial", length = 100, nullable = false)
    private String nome;

    public Long getId() {
        return id;
    }

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

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
}

My SQL

mysql> show tables;
+-----------------+
| Tables_in_teste |
+-----------------+
| tb_aluno        |
+-----------------+
1 row in set (0.00 sec)

mysql>

Oi Bernardo!

Muito bom ter resolvido o seu problema. Caso você descubra o que aconteceu, poste aqui.

Abs.