Я настроил простое приложение Spring-Boot с файлом schema.sql и jparepository для человека объекта.Hibernate:
select
next value for seq_pk_person
Hibernate:
insert
into
person
(name, id)
values
(?, ?)
Очевидно, есть таблица с именем Person . Однако, когда я добавляю AssertJ-DB (3.0.0) с полем подключения и пытаюсь подключиться к этой таблице: < /p>
private AssertDbConnection assertDbConnection = AssertDbConnectionFactory
.of("jdbc:h2:mem:testdb", "sa", "")
.create();
...
Person is written exactly in the same as in the hibernate log above
@Test
public void testPersistPerson() {
Table personTable = assertDbConnection.table("person").build();
Assertions.assertThat(personTable)
.exists();
...
< /code>
Я получаю < /p>
[person table]
Expecting exist but do not exist
java.lang.AssertionError: [person table]
Expecting exist but do not exist
at com.example.demo.PersonRepositoryTest.testPersistPerson(PersonRepositoryTest.java:48)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
< /code>
Я хотел бы понять, что я делаю здесь и как это исправить. Полный проект можно найти здесь. Соответствующие файлы: < /p>
schema.sql:
CREATE TABLE person (
id BIGINT PRIMARY KEY,
name VARCHAR(255) check (length(name) < 10),
job INT
);
CREATE SEQUENCE SEQ_PK_PERSON INCREMENT BY 1;
< /code>
application.yml:
spring:
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
username: sa
password:
initialization-mode: always
jpa:
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: none
show-sql: true
properties.hibernate.format_sql: true
defer-datasource-initialization: true
sql:
init:
mode: always
h2:
console:
enabled: true
< /code>
pperson.java:
package com.example.demo;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@Entity
@Getter
@Setter
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_seq")
@SequenceGenerator(name = "person_seq",
sequenceName = "SEQ_PK_PERSON", allocationSize = 1)
private Long id;
private String name;
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -not-exist