2

Spring logs shows that the table is being created twice within the database, Although the database only shows Single set of tables.

This only happen when I ran mvn verify to run integration test

SpringBoot version 1.5.6

Here is the log

2017-08-14 13:58:00.351  INFO 36636 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-08-14 13:58:00.374  INFO 36636 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-08-14 13:58:00.467  INFO 36636 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-08-14 13:58:00.469  INFO 36636 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-08-14 13:58:00.471  INFO 36636 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-08-14 13:58:00.629  INFO 36636 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-08-14 13:58:00.775  INFO 36636 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
2017-08-14 13:58:01.418  INFO 36636 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2017-08-14 13:58:01.451  INFO 36636 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: album
2017-08-14 13:58:01.454  INFO 36636 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: album
2017-08-14 13:58:01.463  INFO 36636 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: album_image_set
2017-08-14 13:58:01.465  INFO 36636 --- [           main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: album_image_set
...
2017-08-14 13:58:01.658  INFO 36636 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

application.properties

spring.datasource.url = jdbc:hsqldb:mem:manudcamera_api_sandbox
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driver-class-name = org.hsqldb.jdbcDriver
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql = false

Sample Entity Classes, setter/getter is omitted. AbstractEntity Class

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractEntity implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @CreatedDate
    private Date createdDate;

    @LastModifiedDate
    private Date lastModifiedDate;

    @Override
    public abstract int hashCode();

    @Override
    public abstract boolean equals(Object obj);
}

Album

@Entity
public class Album extends AbstractEntity {

    @Column(nullable = false)
    private String uuid;

    @Column(nullable = false)
    private String name;

    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH}, orphanRemoval = true)
    private Set<Image> imageSet = new HashSet<>(0);

}
XPLOT1ON
  • 2,994
  • 2
  • 20
  • 36
  • Are you using sequence for your table creation? – Gökhan Polat Aug 14 '17 at 08:20
  • I not familiar with the term. But I didn't make changes with hibernate configuration, other than what I have posted (application.properties) @GökhanPolat – XPLOT1ON Aug 14 '17 at 09:01
  • Ok, it seems you've not created a sequence for the table. Firstly create a sequence and then try again. I found this question quickly about sequence use with hibernate. [How to create a sequence per table](https://stackoverflow.com/questions/21704934/hibernate-4-and-postgres-how-to-create-a-sequence-per-table) – Gökhan Polat Aug 14 '17 at 10:30
  • I have declared that in my Entity class. It very wired how it only happens when I ran integration test. but not in development – XPLOT1ON Aug 14 '17 at 10:49
  • Added some of my entity class @GökhanPolat – XPLOT1ON Aug 14 '17 at 10:53
  • Are your integration tests also building a spring application context with hibernate? If so, is that context also set for hibernate.ddl-auto=update? That would absolutely cause hibernate to try to create or update the table during the IT run. You should have your ITs set to validate or none instead if you don't already. – tokkov Aug 15 '17 at 18:13
  • Spring manages all application contexts. I annotated each IT class with `@SpringBootTest` and `@RunWith(SpringRunner.class)` – XPLOT1ON Aug 16 '17 at 06:28

0 Answers0