gpt4 book ai didi

java - JPA : entity object is not appeared in the H2 console

转载 作者:太空宇宙 更新时间:2023-11-04 11:22:04 27 4
gpt4 key购买 nike

在我的 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 为空

这是我如何连接到 H2 enter image description here

当我运行我的应用程序时,它说:

[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

所以,看起来,应用程序制作了数据库的架构。我说得对吗?

最佳答案

您需要在application.properties中设置h2配置写下这些行

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb --> whatever url you find when open console
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create

关于java - JPA : entity object is not appeared in the H2 console,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44802676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com