简体   繁体   中英

'ALTER TABLE' cannot be performed because table does not exist

I'm using JPA 2 with Eclipselink 2 and a Derby in memory db for my tests. When I start my little test programm I get the following exception:

[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")

If I try the same with HyperSQL (hsqldb) I get:

[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")

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

Or is something wrong with my example class?

@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 starts by dropping table constraints (the alter statement you're seeing), then the tables, and then recreate everything. Since you are using an in-memory database, there is actually nothing to drop and EclipseLink reports the failed attempts as a warning. Just ignore them.

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