S
S
Stepan Pelmegov2017-01-15 13:00:54
PostgreSQL
Stepan Pelmegov, 2017-01-15 13:00:54

How to fix error when deleting Hibernate tables?

Hello everyone, when starting a project, hibernate throws out a huge sheet of exceptions:

15-Jan-2017 12:51:11.109 INFO [RMI TCP Connection(2)-127.0.0.1] org.hibernate.validator.internal.util.Version.<clinit> HV000001: Hibernate Validator 5.3.4.Final
Hibernate: alter table public.user_role drop constraint FKa68196081fvovjhkek5m97n3y
15-Jan-2017 12:51:12.168 WARN [RMI TCP Connection(2)-127.0.0.1] org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl.handleException GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
 org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
  at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:374)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:331)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:230)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126)
  at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112)
  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:144)
  at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
  at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
  at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
  at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:511)
  at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:495)

Deletion and creation of tables at project startup is configured:
35626103bdd844f785f883e2686069de.png
Relationship between ManyToMany tables.
user table:
@ManyToMany(fetch = FetchType.EAGER, targetEntity = Role.class, cascade = {CascadeType.ALL})
    @JoinTable(name = "user_role", joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<Role> roles;

role table:
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "roles")
    private List<User> users;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2017-01-15
@DarkRaven

I got the impression that not the entire log ...
PostgreSQL (you apparently have it) allows you to execute such a query?
As for the problem itself, you are using schema regen at application startup. Maybe try putting update in place of drop-create?
Something seems to have been written here, but it is not indicated who won: forum.spring.io/forum/spring-projects/data/70844-h...
I would like to add on my own that I would use the migration framework to update the database schema . This will give you better control over database versions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question