java - 无法执行“ALTER TABLE”,因为表不存在

标签 java orm jpa eclipselink derby

我将 JPA 2 与 Eclipselink 2 和内存数据库中的 Derby 一起用于我的测试。当我启动我的小测试程序时,出现以下异常:

[EL Warning]: 2010-08-12 17:17:44.943--ServerSession(948252856)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLSyntaxErrorException: 'ALTER TABLE' cannot be performed on 'ARTICLE_ARTICLE' because it does not exist. Error Code: 30000 Call: ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT RTCLrtclsRltdTThsD Query: DataModifyQuery(sql="ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT RTCLrtclsRltdTThsD")

如果我对 HyperSQL (hsqldb) 进行同样的尝试,我会得到:

[EL Warning]: 2010-08-12 17:47:33.179--ServerSession(1925661675)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: user lacks privilege or object not found: ARTICLE_ARTICLE Error Code: -5501 Call: ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT FK_ARTICLE_ARTICLE_articlesRelatedToThis_ID Query: DataModifyQuery(sql="ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT FK_ARTICLE_ARTICLE_articlesRelatedToThis_ID")

表的生成策略是“drop-and-create”,为什么Eclipselink会告诉我表不存在?

还是我的示例类有问题?

@Entity
public class Article implements Serializable {

    @Id @GeneratedValue
    private int id;
    private String title;
  @ManyToMany(mappedBy = "relatedArticles")
  private Set<Article> articlesRelatedToThis = new HashSet<Article>();
  @ManyToMany(cascade = CascadeType.PERSIST)
  private Set<Article> relatedArticles = new HashSet<Article>();

  public Article() {}

  public Article(String title) {
    this.title = title;
  }

  public int getId() {
    return id;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public Set<Article> getRelatedArticles() {
    return relatedArticles;
  }

  public void addRelatedArticle(Article related) {
    relatedArticles.add(related);
  }

  public void removeRelatedArticle(Article related) {
    relatedArticles.remove(related);
  }

  @PreRemove
  public void preRemove() {
    for(Article article : articlesRelatedToThis)
      article.removeRelatedArticle(this);
  }
}

最佳答案

The table generation strategy is "drop-and-create", so why does Eclipselink tell me that a table would not exist?

EcliseLink 首先删除表约束(您看到的 alter 语句),然后是表,然后重新创建所有内容。由于您使用的是内存数据库,因此实际上没有什么可删除的,并且 EclipseLink 将失败尝试报告为警告。忽略它们。

关于java - 无法执行“ALTER TABLE”,因为表不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3469303/

相关文章:

rest - JPA 2.0 元模型是否可用于确定双向关联的双方

java - @SequenceGenerator 在用@MappedSuperclass 注释的类上

mysql - 我在哪里可以找到从 JPA 实体生成的数据库脚本?

hibernate - 如何防止hibernate在生成的sql中使用模式

java - Jpa语法错误解析

java - NDK 应用程序签名检查

php - Laravel ORM 数组到字符串的转换

java - HTML 到 XML 解析器

java - Android MediaRecorder JNI(Delphi)的问题

Java - 使用::时函数是否在内部接收参数?