为什么"改变表丢弃约束"在使用HSQLDB运行表创建DDL之前执行

时间:2017-09-01 06:03:59

标签: java hibernate jpa hsqldb

我打算利用Spring 4和Hibernate与HSQLDB一起创建一个内存数据库,假设每个单词只有一个词性用于测试目的。

我有两个实体类:

public class Word {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;

  private String word;

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="PARTOFSPEECH_ID", insertable=false,updatable=false)
  private PartOfSpeech partOfSpeech;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getWord() {
    return word;
  }

  public void setWord(String word) {
    this.word = word;
  }

  public PartOfSpeech getPartOfSpeech() {
    return partOfSpeech;
  }

  public void setPartOfSpeech(PartOfSpeech partOfSpeech) {
    this.partOfSpeech = partOfSpeech;
  }
}

public class PartOfSpeech {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  private String partOfSpeech;
  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getPartOfSpeech() {
    return partOfSpeech;
  }

  public void setPartOfSpeech(String partOfSpeech) {
    this.partOfSpeech = partOfSpeech;
  }
}

使用上面的代码我使用Hibernate运行Spring并看到一个非常奇怪的WARN

Hibernate: alter table Word drop constraint FKp318rmy36es1v4gqwr8nkaxbs
Sep 01, 2017 8:42:09 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement

...

Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.WORD
  at org.hsqldb.error.Error.error(Unknown Source)
  at org.hsqldb.error.Error.error(Unknown Source)
  at org.hsqldb.SchemaManager.getUserTable(Unknown Source)
  at org.hsqldb.ParserDDL.compileAlterTable(Unknown Source)
  at org.hsqldb.ParserDDL.compileAlter(Unknown Source)
  at org.hsqldb.ParserCommand.compilePart(Unknown Source)
  at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
  at org.hsqldb.Session.executeDirectStatement(Unknown Source)
  at org.hsqldb.Session.execute(Unknown Source)
  ... 111 more

我无法理解为什么当@ManyToOne@JoinColumn注释添加到Word实体时,hibernate执行的第一个SQL语句是alter table Word drop constraint我的期望:(

所以任何人都可以提供帮助吗?如何删除alter table前置语句,以使令人讨厌的WARN堆栈跟踪消失?

0 个答案:

没有答案