Java Can';t从实体Spring引导生成表
请帮忙!!!我无法从实体**生成表:Java Can';t从实体Spring引导生成表,java,spring,spring-boot,jpa,Java,Spring,Spring Boot,Jpa,请帮忙!!!我无法从实体**生成表: // class Application import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; @EntityScan("sb.ent
// class Application
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
@EntityScan("sb.entity")
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
//文件pom.xml
4.0.0
某人
**请确保已将应用程序类程序包正确放置在程序包下。例如,如果您的Application.java(包含main)位于com.sb下,那么sb.java实体类应该位于com.sb包下
另一个例子
com.sb-->Application.java
com.sb.enity-->CategoryEntity.java
com.notscanned.test-->NotScannedCategoryEntity.java
层次结构很重要,com.sb.*下的任何内容都将在spring前自动屏蔽
希望这能解决您的问题。请确保您已将应用程序类包正确放置在包下。例如,如果您的Application.java(包含main)位于com.sb下,那么sb.java实体类应该位于com.sb包下
另一个例子
com.sb-->Application.java
com.sb.enity-->CategoryEntity.java
com.notscanned.test-->NotScannedCategoryEntity.java
层次结构很重要,com.sb.*下的任何内容都将在spring前自动屏蔽
希望这能解决您的问题。创建实体时,需要提供@Id注释。这是强制性的。我假设你是因为同样的原因而出错的。您可以尝试创建实体为吗
package sb.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "category")
public class CategoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@Column(name = "name")
private String name;
@Column(name = "code")
private String code;
}
创建实体时,需要提供@Id注释。这是强制性的。我假设你是因为同样的原因而出错的。您可以尝试创建实体为吗
package sb.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "category")
public class CategoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@Column(name = "name")
private String name;
@Column(name = "code")
private String code;
}
应用程序在哪个包中?@SimonMartinelli我只是为我的项目添加了图像,请观看并帮助我如果您将应用程序移动到sb包中,那么您将不需要任何*扫描注释。请尝试停止混合来自不同版本框架的jar。您正在混合Hibernate 4和Hibernate 5,不知道为什么它不工作。。。只需删除org.hibernate
dpendencies,它们已经由spring boot starter数据jpa
模块管理。尝试添加@ComponentScan(“基本包名”)和@Configuration annotations to main class因为它们都在不同的包中,所以您需要明确指出哪个包是应用程序?@SimonMartinelli我只是为我的项目添加了图像,请注意并帮助我如果您将应用程序移动到sb包中,那么您将不需要任何*扫描注释。请尝试停止混合来自不同版本框架的jar。您正在混合Hibernate 4和Hibernate 5,不知道为什么它不工作。。。只需删除org.hibernate
dpendencies,它们已经由spring boot starter data jpa
模块管理。尝试将@ComponentScan(“基本包名”)和@Configuration注释添加到主类中,因为它们都位于需要明确提及的不同包中
// file pom.xml
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sb</groupId>
<artifactId>sb</artifactId>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<properties>
<mysql.version>8.0.13</mysql.version>
<java.version>1.8</java.version>
</properties>
<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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package sb.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "category")
public class CategoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
@Column(name = "name")
private String name;
@Column(name = "code")
private String code;
}