i am trying to write @DataJpaTest but i want to load just one repository and entity. However hibernate doesn’t create table for this entity.
@DataJpaTest()
@Import({ClockFactory.class, JpaTestConfig.class})
@ActiveProfiles("integration")
class CustomRepositoryTest {
@Autowired
private CustomRepository customRepository;
@Autowired
private DataSource dataSource;
@Autowired
private ApplicationContext context;
@Test
void connectionEstablished() {
customRepository.save(CustomEntity.builder()
.id(1)
.company("firma")
.build());
}
}
with config:
@TestConfiguration
@EnableAutoConfiguration(exclude = {JpaRepositoriesAutoConfiguration.class})
@EnableJpaRepositories(basePackageClasses = CustomRepository.class)
@EntityScan(basePackageClasses = CustomEntity.class)
public class JpaTestConfig {
}
and with properties:
spring:
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
generate-ddl: true
However when I try to run the test, i am getting that table doesn’t exist. But what also strange is – in logs i can see that hibernate is trying to create table:
Hibernate: drop table if exists custom_table cascade
Hibernate: create table custom_table....