0

I am creating a simple REST API via Google app engine. I have Task and Project objects. A Project can have one or more Tasks. Here is some details about these data objects:

@Entity
public class Project implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;
    private String title;
    private String description;
    private Date createdAt;

    // Section 1
    // @OneToMany(mappedBy = "project")
    // private List<Task> tasks;

    // ...
}

@Entity
public class Task implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Key id;
    private String shortDescription;
    private String longDescription;
    private Date createdAt;
    private Date dueDate;
    private boolean completed;

    // Section 2
    // @ManyToOne
    // @JoinColumn(name = "id_project")
    // private Project project;

    // ...
}

The way I implemented the class above works fine (Section 1 and Section 2 are commented out). However, what I want to do is to relate Task objects to Project. Whenever I remove the comments above and activate Section 1 and Section 2 the errors below occur.

The error appears for Project operations

HTTP ERROR 500

Problem accessing /api/project. Reason:

    Could not initialize class com.aspect.todo.dao.EMFService
Caused by:

java.lang.NoClassDefFoundError: Could not initialize class com.aspect.todo.dao.EMFService
    at com.aspect.todo.dao.Dao.getProjects(Dao.java:144)
    at com.aspect.todo.server.ProjectService.get(ProjectService.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    ...

The error appears for Task operations

HTTP ERROR 500

Problem accessing /api/task. Reason:

    INTERNAL_SERVER_ERROR
Caused by:

java.lang.ExceptionInInitializerError
    at com.aspect.todo.dao.Dao.getTasks(Dao.java:98)
    at com.aspect.todo.server.TaskService.get(TaskService.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    ...


Caused by:

javax.persistence.PersistenceException: Provider error. Provider: org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider
    at javax.persistence.Persistence.createFactory(Persistence.java:176)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:112)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:66
    ...


Caused by:

Errors were encountered when initialising the specified MetaData. See the nested exceptions for details
org.datanucleus.exceptions.NucleusUserException: Errors were encountered when initialising the specified MetaData. See the nested exceptions for details
    at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:892)
    at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:794)
    at org.datanucleus.jpa.EntityManagerFactoryImpl.initialisePMF(EntityManagerFactoryImpl.java:488)
    ...

Caused by:

Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!! Please enhance the class before running DataNucleus.
org.datanucleus.exceptions.NucleusUserException: Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!! Please enhance the class before running DataNucleus.
    at org.datanucleus.metadata.MetaDataManager.initialiseClassMetaData(MetaDataManager.java:2225)
    at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaData(MetaDataManager.java:2176)
    at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:881)
    ...

The weird thing is when I start with these sections commented out, compile and run and then activate only Section 2 and rerun it works fine. If close and reopen Eclipse try again the error occurs again.

NOTE: Datanucleus JDO/JPA version: v1

mert
  • 1,942
  • 2
  • 23
  • 43

4 Answers4

0
Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!!
Please enhance the class before running DataNucleus.

The fact is that the classes are not enhanced at runtime and you have to find a way to enhance them prior to runtime that works for your environment ... Maven, Ant, command-line, DataNucleus Eclipse plugin, or GAE Eclipse plugin.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • 2
    Under Project Properties > Google > App Engine > ORM, I explicitly listed my classes above (despite there is /src folder, which includes them already). Still the same problem. – mert Dec 01 '12 at 14:48
  • so you're using the GAE Eclipse plugin (supported only by Google, try their google group), and as I said there are many other options. Try one of the others – DataNucleus Dec 01 '12 at 14:50
0

If you are using ANT then add the below lines in your build.xml before </project> tag close

<target name="datanucleusenhance" depends="compile"
  description="Performs JDO enhancement on compiled data classes.">
<enhance_war war="war" />

And give the following command when build the ant "ant datanucleusenhance runserver"

Hope this is useful, it took me a while to find the solution.

Satish Bellapu
  • 740
  • 1
  • 5
  • 15
0

Just upgrade your GAE SDK, it solved the problem for me.

0

Found Meta-Data for class com.aspect.todo.model.Task but this class is not enhanced!! Please enhance the class before running DataNucleus.

I'll show here a way to enhance classes in Gradle environment. Use the following configuration.

  • Dependencies:

    dependencies {
        appengineSdk 'com.google.appengine:appengine-java-sdk:<version>'
        compile 'org.datanucleus:datanucleus-enhancer:<version>'
        compile 'org.datanucleus:datanucleus-api-jpa:<version>'  // or datanucleus-api-jdo
        /* other dependencies */
    }
    
  • Plugin:
    (for gradle-appengine-plugin version 1.9.5 or higher)

    appengine {
        enhancer {
            version = "v2"
            api = "jpa"  // or "jdo"
            enhanceOnBuild = true
        }
        /*...*/
    }
    

    (for older versions of gradle-appengine-plugin)

    appengine {
        enhancerVersion = "v2"
    }
    

    To make enhance run automatically before creating the war in your build.gradle file:

    war.dependsOn appengineEnhance
    

If you have problems executing task :appengineEnhance, try to run it with --stacktrace (to view the stacktrace) or --info (to find the location of the error log file) options.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259