【发布时间】:2017-12-01 19:54:15
【问题描述】:
在我的 spring 应用程序中,我有以下实体:
import lombok.Data;
@Data
@Entity
public class Profile {
@Id
@GeneratedValue
Long id;
String name;
String address;
String description;
String img;
public Profile(String name, String address, String description, String img) {
this.name = name;
this.address = address;
this.description = description;
this.img = img;
}
}
然后存储库是:
@Repository
public interface ProfileRepository extends JpaRepository<Profile,Long> {
}
这是我的pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
所以,我希望当我转到 h2 控制台 uri 时:
http://localhost:8080/h2-console/login.do?jsessionid=ae6ba7021a23e0ebb4a4844381546e72
它显示了与对象Profile 相关的表。
问题是:没有名为 Profile 的表。
那么,为什么我没有个人资料表?
application.properties 为空
当我运行我的应用程序时,它会说:
[2m2017-06-29 10:07:21.106[0;39m [32m INFO[0;39m [35m51392[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.hibernate.dialect.Dialect [0;39m [2m:[0;39m HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
[2m2017-06-29 10:07:21.557[0;39m [32m INFO[0;39m [35m51392[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.hibernate.tool.hbm2ddl.SchemaExport [0;39m [2m:[0;39m HHH000227: Running hbm2ddl schema export
[2m2017-06-29 10:07:21.557[0;39m [32m INFO[0;39m [35m51392[0;39m [2m---[0;39m [2m[ restartedMain][0;39m [36morg.hibernate.tool.hbm2ddl.SchemaExport [0;39m [2m:[0;39m HHH000230: Schema export complete
看来,应用程序制作了数据库的架构。我说的对吗?
【问题讨论】:
-
因为需要指示 SpringBoot 创建 Schema。 docs.spring.io/spring-boot/docs/current/reference/html/… 和 stackoverflow.com/questions/29758136/…
-
请分享您的 application.properties
-
@Salman 现在您在
application.properties中设置了一个数据库名称:dbname。因此,当您尝试从 H2 控制台 (http://localhost:8080/h2-console) 连接到 db 时,您必须使用jdbc:h2:mem:dbname作为“JDBC URL”。您必须从 IDE(或通过 SQL 工具)使用端口 9092 连接到 H2 DB 服务器。
标签: java spring hibernate maven spring-data-jpa