简体   繁体   中英

Spring-data-jpa + Hibernate not creating expected table

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM