4

Before you assume this is a duplicate, I'm aware of these answers (among others):

Still, auto-creating a table doesn't work!

I've used different versions of Hibernate, Spring, even implemented class JpaConfig from JpaBaseConfiguration, and adding deference properties from common application properties

Expected result:

Running hbm2ddl schema update

Actual result:

Running hbm2ddl schema export

I see org.hibernate.cfj.Configuration Iterator<Table> getTableMappings() , but this method return emty list instead mapping class->table

Any help would be appreciated.

Application.yml:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/task-manager
    username: postgres
    password: password
    schema: public
  jpa:
    generate-ddl: true
    hibernate:
      naming-strategy: ru.ssau.common.naming_strategy.CustomNamingStrategy
      ddl-auto: create-drop

logging:
  level:
    org:
      hibernate:
        SQL: DEBUG
        type:
          descriptor:
            sql:
              BasicBinder: TRACE

Adding property driverClassName doesn't resolve it:

My entity:

@Entity(name = "simple_user")
public class User extends PersistentObject {

    @Column(unique = true, nullable = false)
    private String nickname;


    @OneToOne
    @JoinColumn(name = "user_account_id")
    private UserAccount userAccount;

    public User() {
    }

    public User(String nickname) {
        this.nickname = nickname;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public UserAccount getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(UserAccount userAccount) {
        this.userAccount = userAccount;
    }
}

Hibernate's output from console:

HHH000412: Hibernate Core {4.3.11.Final}
HHH000206: hibernate.properties not found
HHH000021: Bytecode provider name : javassist
HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
HHH000397: Using ASTQueryTranslatorFactory
HHH000227: Running hbm2ddl schema export
HHH000230: Schema export complete
Community
  • 1
  • 1
Dmitry
  • 73
  • 2
  • 11

2 Answers2

1

Just add to your configuration following :

spring:
  jpa:
    hibernate:
        ddl-auto: none
    properties:
        hibernate.hbm2ddl.auto: create-drop

Works well for me, using 1.4.3.RELEASE.

Ilya Dyoshin
  • 4,459
  • 1
  • 19
  • 18
  • 1
    Yes, I've added this property, but it doesn't work :( – Dmitry Jan 14 '17 at 18:57
  • might be it is required to run this twice: (you have had a database structure from your previous run, which haven't been dropped, so during startup hibernate will try to create the database structure, but will fail, because tables already present; then you stop your application and drop cycle works. within next startup the structure should be created) – Ilya Dyoshin Jan 14 '17 at 20:18
  • nevertheless hibernate's ddl-auto routines are bad practice, from my point of view. I personally use this during my unit-tests. and for production and integration testing I do use liquibase, which I highly recommend to introduce in project. – Ilya Dyoshin Jan 14 '17 at 20:20
  • I did this way 1) Delete old database 2) Create new empty database with old name (task-manager) Thank you for idea with liquibase. I'll try it later. – Dmitry Jan 14 '17 at 20:41
-2

I'm facing the same, but in my case just one of the various entitys is not automaticaly created on my database, let´s try to solve together.

My entitys seens like:

@Entity
@Table(name = "tablename")
public class ClassName {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

    private long id;
    ...

Try to put the annotations like above and tell me if works.

Tks.