Search code examples
javaspring-bootjpah2

I saw the table creation operation in the IDEA console, but I don't see the table in the H2 page


Below is the entity code,We can see the SQL creation statements for the relevant tables in the Idea console.

@Entity
@Table(name = "MED_PGW")
@NoArgsConstructor
@Data
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class MedPgwEntity implements Serializable {

    private static final long serialVersionUID = -1L;
    @Id
    //@GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "key_field")
    private String keyField;

    @Column(name = "body")
    private String body;

    @CreatedDate
    @Column(name = "create_time")
    private Date createTime;


    @LastModifiedDate
    @Column(name = "update_time")
    private Date updateTime;

}

idea console

2024-02-19 16:53:39.261 [] [main] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table if exists customer CASCADE 
Hibernate: drop table if exists med_pgw CASCADE 
Hibernate: drop sequence if exists hibernate_sequence
Hibernate: create sequence hibernate_sequence start with 1 increment by 1
Hibernate: create table customer (id bigint not null, email varchar(255), name varchar(255), primary key (id))
Hibernate: create table med_pgw (key_field varchar(255) not null, body varchar(255), create_time timestamp, update_time timestamp, primary key (key_field))

application.yml

spring:
  datasource:
    druid:
#      url: jdbc:h2:mem:test
      url: jdbc:h2:mem:test
      username: med
      password: med
      driver-class-name: org.h2.Driver
  jpa:
    hibernate:
      ddl-auto: create-drop
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.H2Dialect
  h2:
    console:
      enabled: true
    path: /h2-console

login page

Saved Settings:Generic H2 (Server)
Setting Name:Generic H2 (Server)
Driver Class:org.h2.Driver
JDBC URL:jdbc:h2:mem:test
User Name:med
Password:med

result

I saw the table creation operation in the IDEA console, but I don't see the table in the H2 page.

I hope to see the information of the created tables on this page.


Solution

  • Missing druid jar package, just import the jar package.

            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>1.2.8</version>
            </dependency>
    

    or modify application.yml

    spring:
      datasource:
        url: jdbc:h2:mem:test
        username: med
        password: med
        driver-class-name: org.h2.Driver