繁体   English   中英

DataNucleus类不是持久异常

[英]DataNucleus Class not Persistable Exception

我试图用数据核jdo(和neodatis作为数据存储库)制作一些基本的持久化类。

我有以下三个课程(已从本教程复制)

库存.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;}
}

产品.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;}

}

和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;
}    
}

自从构建项目时我就已经正确地增强了所有这些功能:

(...)
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
(...)

在运行应用程序时,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.

我无法弄清楚为什么,有人可以给我提示吗?

多年后,同样的症状。 就我而言,我在堆栈跟踪中得到了相同的错误和3条建议。 但是对我来说,实际的问题不是这些,而是​​我在Eclipse和Google上运行的。 App Engine设置未同时选中“启用本地HRD支持”和“用户Datanucleous JDO / JPA访问数据存储区”。 一旦检查了这些项目,便能够使用与以前相同的代码来持久保存,并且没有出现上述错误。

如果您的增强程序在Eclipse中保存文件时运行,请注意以查看它是否在Eclipse控制台中得到了增强。 我注意到我安装的Eclipse偶尔会忘记增强类。 如果忘记了,它将把该类部署到未增强的GAE。 只需重新启动Eclipse即可达到目的。

试试吧:

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM