【发布时间】:2011-03-29 00:17:33
【问题描述】:
我将 JPA 2 与 Eclipselink 2 和内存数据库中的 Derby 用于我的测试。当我开始我的小测试程序时,我得到以下异常:
[EL 警告]:2010-08-12 17:17:44.943--ServerSession(948252856)--异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse。 persistence.exceptions.DatabaseException 内部异常:java.sql.SQLSyntaxErrorException:“ALTER TABLE”不能在“ARTICLE_ARTICLE”上执行,因为它不存在。 错误代码:30000 调用:ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT RTCLrtclsRltdTThsD 查询:DataModifyQuery(sql="ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT RTCLrtclsRltdTThsD")
如果我对 HyperSQL (hsqldb) 进行同样的尝试,我会得到:
[EL 警告]:2010-08-12 17:47:33.179--ServerSession(1925661675)--异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse。 persistence.exceptions.DatabaseException 内部异常:java.sql.SQLException:用户缺少权限或找不到对象:ARTICLE_ARTICLE 错误代码:-5501 调用:ALTER TABLE ARTICLE_ARTICLE DROP CONSTRAINT FK_ARTICLE_ARTICLE_articlesRelatedToThis_ID 查询: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);
}
}
【问题讨论】:
标签: java orm jpa eclipselink derby