###前提・実現したいこと
https://allabout.co.jp/gm/gc/80742/
こちらの記事を参考にJDOの保存、取得の学習をしています。
PersistentManagerの操作でエラーが出てしまい困っています。
ご教授ください。よろしくお願いします。
###発生している問題・エラーメッセージ
org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class "jp.allabout.SampleData" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
…
NestedThrowablesStackTrace:
The class "jp.allabout.SampleData" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
org.datanucleus.exceptions.ClassNotPersistableException: The class "jp.allabout.SampleData" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
…
###該当のソースコード
#####SampleData.java
package jp.allabout;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class SampleData {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String message;
@Persistent
private String account;
@Persistent
private Date date;
public SampleData(){}
public SampleData(String message,String account,Date date){
this.message = message;
this.account = account;
this.date = date;
}
public Long getId() {
return id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public Date getDate() {
return date;
}
}
#####Gae_addServlet.java
package jp.allabout;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class Gae_addServlet extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("can not access!!");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse resp)
throws IOException {
request.setCharacterEncoding("UTF-8");
String message = request.getParameter("message");
String account = request.getParameter("account");
Date date = Calendar.getInstance().getTime();
SampleData data = new SampleData(message,account,date);
PersistenceManagerFactory pmf = PMF.get(); PersistenceManager pm = pmf.getPersistenceManager(); try { pm.makePersistent(data); } finally { pm.close(); } resp.sendRedirect("/index.jsp");
}
}
###試したこと
ファイルにアクセスできているかの確認はできましたのでパスによるエラーではないと思います。
Gae_addServlet.javaのtry文をコメントアウトするとエラーが出なくなります。
protected void doPost(...) {
...
try {
pm.makePersistent(data);
} finally {
pm.close();
}
...
}
###補足情報(言語/FW/ツール等のバージョンなど)
Java HTML Eclipse(4.4.2)
あなたの回答
tips
プレビュー