gpt4 book ai didi

java - DataNucleus 类不可持久异常

转载 作者:行者123 更新时间:2023-11-29 09:30:43 24 4
gpt4 key购买 nike

我试图用 datanucleus 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
(...)

但是

当运行应用程序时,持久性管理器很好地启动,但是当它试图使某些东西持久化时,会抛出这个异常

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 以访问数据存储区”。一旦我检查了这些项目,我就能够坚持使用与以前相同的代码,并且没有出现上述错误。

关于java - DataNucleus 类不可持久异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14615830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com