简体   繁体   中英

DataNucleus Class not Persistable Exception

I was trying to made some basic persistent classes with datanucleus jdo(and neodatis as datastore).

I have the following three classes(copied fom the tutorial)

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

@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

@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

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. However for me the actual problem was none of those, but that I was running in Eclipse and on the Google | App Engine settings had not checked both "Enable local HRD support" and "User Datanucleous JDO/JPA to access the datastore". 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. I notice that my install of Eclipse forgets to enhance classes every once in a while. If it forgets, it will deploy the class to GAE not enhanced. Simply restarting Eclipse does the trick.

try it:

@Entity // use this annotation 
public class MyClass
{
@Id
long id;

@Basic
@Convert(converter=URLStringConverter.class)
URL url;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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