English 中文(简体)
无法在我sql数据库中生成表格的跳板
原标题:spring boot unable to generate tables in mysql database

I am trying to update the data base schema from defiend JpaEntities but spring boot is not able to generate the database tables. Log file:

申请。 财产档案:

spring.datasource.url= jdbc:mysql://localhost:3306/banque_db
spring.datasource.username= root
spring.datasource.password=
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto= update
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

客户实体类别:

 @Entity(name="client")
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long code;
private String name;
private String email;
@OneToMany(mappedBy = "compte")
private Collection<Compte> comptes;
// + getters and setters

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.0.RELEASE com.Tuto

<artifactId>MaBanque</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MaBanque</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>       
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</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>

最佳回答

actually, the issue was the entity classes were not in the right package. org.example that contains the main class and org.entities for some reason spring boot did not generate the tables so when i moved the entity package to become like org.example.entities and run the app , all the tables where successfully generated. thank you guys for help I appriciate :)

问题回答

页: 1

See docs for more details.

First problem: The application.properties file:

  1. If you set attribute spring.jpa.hibernate.ddl-auto = update, it will not create the schema for you. Instead, it will, you know, update the existing database, which you currently does not have.
  2. The default value for spring.jpa.hibernate.ddl-auto is create-drop but you are overriding it.
  3. Your application.properties must be in

src/main/resources

页: 1

=>

春季,jpa.hibernate.dl-auto = 创造 - 下降

Second problem: The entity class. You should add @Column on top of the attributes, like so:

`@Entity(name="client")
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long code;
@Column
private String name;
@Column
private String email;
@OneToMany(mappedBy = "compte")
private Collection<Compte> comptes;
// + getters and setters`

@EntityScan(basePackages = {"com.acme.model"}) // force scan JPA entities public class Application





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签