[英]DataNucleus Class not Persistable Exception
I was trying to made some basic persistent classes with datanucleus jdo(and neodatis as datastore). 我试图用数据核jdo(和neodatis作为数据存储库)制作一些基本的持久化类。
I have the following three classes(copied fom the tutorial) 我有以下三个课程(已从本教程复制)
inventory.java 库存.java
@PersistenceCapable
public class Inventory {
@PrimaryKey
String name = null;
Set<Product> products = new HashSet();
public Inventory(String name)
{
this.name = name;}
public Set<Product> getProducts() {return products;}
}
Product.java 产品.java
@PersistenceCapable
public class Product {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.INCREMENT)
long id;
String name = null;
String description = null;
double price = 0.0;
public Product(String name, String desc, double price)
{
this.name = name;
this.description = desc;
this.price = price;}
}
and book.java 和book.java
@PersistenceCapable
public class Book extends Product {
String author=null;
String isbn=null;
String publisher=null;
public Book(String name, String desc, double price, String author,
String isbn, String publisher)
{
super(name,desc,price);
this.author = author;
this.isbn = isbn;
this.publisher = publisher;
}
}
all of them should have been correctly enhanched since when building the project i get this: 自从构建项目时我就已经正确地增强了所有这些功能:
(...)
gen 31, 2013 12:10:14 AM org.datanucleus.enhancer.DataNucleusEnhancer main
INFO: DataNucleus Enhancer (version 3.2.0.m2) for API "JDO" using JRE "1.7"
ENHANCED (PersistenceCapable) : minchiabbasta.Book
ENHANCED (PersistenceCapable) : minchiabbasta.Inventory
ENHANCED (PersistenceCapable) : minchiabbasta.Product
(...)
BUT 但
when running the application the Persistence manager fire up nicely, but when it try to make something persistent this exception get thrown 在运行应用程序时,Persistence Manager会很好地启动,但是当它尝试使某些东西持久化时,会抛出此异常
org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class
"minchiabbasta.Inventory" 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.
I can't manage to figure out why, can someone give me a hint? 我无法弄清楚为什么,有人可以给我提示吗?
Years later, same symptom. 多年后,同样的症状。 In my case I got the same error and 3 suggestions on the stack trace.
就我而言,我在堆栈跟踪中得到了相同的错误和3条建议。 However for me the actual problem was none of those, but that I was running in Eclipse and on the Google |
但是对我来说,实际的问题不是这些,而是我在Eclipse和Google上运行的。 App Engine settings had not checked both "Enable local HRD support" and "User Datanucleous JDO/JPA to access the datastore".
App Engine设置未同时选中“启用本地HRD支持”和“用户Datanucleous JDO / JPA访问数据存储区”。 Once I checked those items I was able to persist using the same code as before, and did not get the above error.
一旦检查了这些项目,便能够使用与以前相同的代码来持久保存,并且没有出现上述错误。
If your enhancer runs upon saving files in Eclipse, take notice to see if it enhances in the Eclipse console. 如果您的增强程序在Eclipse中保存文件时运行,请注意以查看它是否在Eclipse控制台中得到了增强。 I notice that my install of Eclipse forgets to enhance classes every once in a while.
我注意到我安装的Eclipse偶尔会忘记增强类。 If it forgets, it will deploy the class to GAE not enhanced.
如果忘记了,它将把该类部署到未增强的GAE。 Simply restarting Eclipse does the trick.
只需重新启动Eclipse即可达到目的。
try it: 试试吧:
@Entity // use this annotation
public class MyClass
{
@Id
long id;
@Basic
@Convert(converter=URLStringConverter.class)
URL url;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.