簡體   English   中英

Spring-data-jpa + Hibernate沒有創建預期的表

[英]Spring-data-jpa + Hibernate not creating expected table

在你認為這是重復之前,我知道這些答案(以及其他答案):

不過,自動創建表格不起作用!

我使用的不同版本HibernateSpring ,甚至實現類JpaConfigJpaBaseConfiguration從,並加入順從性普遍應用性能

預期結果:

運行hbm2ddl架構更新

實際結果:

運行hbm2ddl架構導出

我看到org.hibernate.cfj.Configuration Iterator<Table> getTableMappings() ,但這個方法返回emty列表而不是映射class-> table

任何幫助,將不勝感激。

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

添加屬性driverClassName無法解析它:

我的實體:

@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從控制台輸出:

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

只需添加以下配置:

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

適用於我,使用1.4.3.RELEASE。

我面臨同樣的問題,但在我的情況下,我的數據庫中沒有自動創建其中一個實體,讓我們一起解決。

我的實體看起來像:

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

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

    private long id;
    ...

嘗試將上述注釋放在一起,告訴我是否有效。

韓國社交協會。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM