我正在尝试创建在eclipse中连接到derby数据库的web应用程序。我在项目方面添加了JPA方面。当我尝试从实体生成表时,我收到错误。这是stacktrace的第一位:
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program`enter code here`
{
static void Main(string[] args)
{
using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt");
using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
{
writer.WriteLine("Information about this package.");
writer.WriteLine("========================");
}
}
}
}
}
}
以下是代码:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: org.eclipse.persistence.dynamic.DynamicClassLoader@2a742aa2
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [lv10example] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class ba.fet.rwa.lv10.domain.Answer] uses a non-entity [class ba.fet.rwa.lv10.domain.Question] as target entity in the relationship attribute [field listOfQuestions].
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.buildEntityManagerFactory(Main.java:94)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:80)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [lv10example] failed.
这是另一个类:
@Entity
public class Answer {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
@Column(name = "id")
private int id;
private String text;
private boolean correctStatus;
@ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(name="QuestionAnswer",joinColumns=@JoinColumn(name="answerID",
referencedColumnName="id"), inverseJoinColumns=@JoinColumn(name="questionID",
referencedColumnName="id"))
private Collection<Question> listOfQuestions;
public Answer() {
id=0;
text="";
correctStatus=false;
listOfQuestions=null;
}
public Answer(int _id, String _text, boolean _correctStatus,Question question){
id=_id;
text=_text;
correctStatus=_correctStatus;
listOfQuestions.add(question);
}
... Getters and setters ...
}
这是persistence.xml
@Entity
@Table(schema = "TEST")
public class Question {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
@Column(name = "id")
private int id;
private String text;
private boolean answered;
private int points;
@ManyToMany(mappedBy="listOfQuestions")
private Collection<Quiz> listOfQuizzes;
@ManyToMany(mappedBy="listOfQuestions")
private Collection<Answer> listOfAnswers;
public Question() {
id=0;
text="";
answered=false;
points=0;
listOfAnswers=null;
}
public Question(int _id,String _text, int _points,Answer answer){
id=_id;
text=_text;
answered=false;
points=_points;
listOfAnswers.add(answer);
}
... Getters and setters ...
}
有人可以帮我吗?这里肯定有错误,但我找不到它。也许这是jpa facet的问题?我试着从现在开始调试2天,但没有运气。对不起,我的英语不好。谢谢! : - )