我是Spring Mvc的新手,我试图通过hibernate创建数据库表。我之前已经完成了,但现在桌子没有创建,我无法弄清楚错误。
MY MODEL CLASS:
@Entity
public class User implements Serializable, UserGetters{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Column(unique=true)
private String logonEmail;
private String name;
@Column(updatable=false)
private String password;
@JsonIgnore
@Column(nullable = false, columnDefinition = "TINYINT(1)")
private boolean isEmailVerified;
// getters and setters
}
Application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/basicdb?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=ace123
spring.data.rest.basePath=/api
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=create
allowed.origins=http://localhost:9000
logging.level.org.springframework.security=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.com.reservos=DEBUG
logging.level.com.sendgrid=DEBUG
logging.level.org.hibernate.tool.hbm2ddl=debug
server.port=3000
的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>org.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<!-- tag::tests[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- end::tests[] -->
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
当我运行代码时,mysql workbench会创建数据库,但不会在其中创建User表。如果有人能帮助我,我会很高兴
答案 0 :(得分:0)
有几种可能的原因:
您的实体类与您使用@EnableAutoConfiguration类相关的实体类相同或位于子包中。如果没有,那么你的spring应用程序看不到它们,因此不会在db
中创建任何内容检查您的配置
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=test
spring.datasource.password=
您的application.properties必须位于src / main / resources文件夹中。
如果你没有正确指定方言,它可能会尝试默认与boot in-memory数据库捆绑在一起我可以看到它尝试连接到本地HSQL(请参阅控制台输出)实例并且无法更新架构。
答案 1 :(得分:0)
尝试删除:
spark-submit --conf