1

Hi I have an entity class annotated with @Entity so it could be persisted with JPA on google app engine.

My class looks like this:

@Entity
public class DataUrls {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

private String postalCode;

private List<String> urls;

public Key getKey() {
    return key;
}

public void setKey(Key key) {
    this.key = key;
}

public String getPostalCode() {
    return postalCode;
}

public void setPostalCode(String postalCode) {
    this.postalCode = postalCode;
}

public List<String> getUrls() {
    return urls;
}

public void setUrls(List<String> urls) {
    this.urls = urls;
}
}

I'm using maven to build my project and at compile phase enhance the classes, in my logging I see the following:

[INFO] --- maven-datanucleus-plugin:3.1.1:enhance (default) @ grabby-backend ---
[INFO] DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
DataNucleus Enhancer completed with success for 1 classes. Timings : input=181 ms,     enhance=60 ms, total=241 ms. Consult the log for full details

[ERROR] --------------------
[ERROR]  Standard error from the DataNucleus tool +     org.datanucleus.enhancer.DataNucleusEnhancer :
[ERROR] --------------------
[ERROR] Nov 14, 2013 5:00:01 PM org.datanucleus.enhancer.DataNucleusEnhancer <init>
INFO: DataNucleus Enhancer for API "JPA"
Nov 14, 2013 5:00:02 PM org.datanucleus.enhancer.DataNucleusEnhancer main
INFO: DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
Nov 14, 2013 5:00:02 PM org.datanucleus.metadata.MetaDataManager loadFiles
WARNING: Metadata file -enhancerName not found in CLASSPATH
Nov 14, 2013 5:00:02 PM org.datanucleus.metadata.MetaDataManager loadFiles
WARNING: Metadata file ASM not found in CLASSPATH
Nov 14, 2013 5:00:02 PM org.datanucleus.enhancer.AbstractClassEnhancer save
INFO: Writing class file "/Development/datagrabber-backend/grabby-    backend/target/classes/com/appspot/datagrabby/model/entities/DataUrls.class" with enhanced     definition
Nov 14, 2013 5:00:02 PM org.datanucleus.enhancer.DataNucleusEnhancer addMessage
INFO: DataNucleus Enhancer completed with success for 1 classes. Timings : input=181 ms,     enhance=60 ms, total=241 ms. Consult the log for full details

and the config in maven looks like this:

<plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>maven-datanucleus-plugin</artifactId>
            <version>${datanucleus.jpa.version}</version>

            <configuration>
                <api>JPA</api>
                <metadataIncludes>com/appspot/blabla/model/entities/*.class</metadataIncludes>
                <verbose>true</verbose>
                <enhancerName>ASM</enhancerName>
            </configuration>

            <dependencies>
                <dependency>
                    <groupId>org.datanucleus</groupId>
                    <artifactId>datanucleus-core</artifactId>
                    <version>${datanucleus.jpa.version}</version>
                </dependency>
            </dependencies>

            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

the persistence code:

    public void persistDataURLs(DataUrls dataUrls){
        EntityManager em = EMF.getFactory().createEntityManager();
        em.persist(dataUrls);
        em.close();
    }

However when I try to write to the database I get following message:

Type ("XXX") is not that of an entity but needs to be for this operation

I understand why the application is saying this, however since the logging of the enhancer plugin notifies that the class is enhanced I wonder why this is happening.

J.Pip
  • 4,523
  • 7
  • 31
  • 49
  • perhaps your persistence code is of relevance here ? since you say it causes some exception (which also has a stack trace). – DataNucleus Nov 14 '13 at 16:10
  • Since I'm running the dev server through maven I don't get a stacktrace, I've added the persistence code though. When I go into debug and check the object I see a lot of JDO stuff like a jdoStateManager and jdoDetachedState. – J.Pip Nov 14 '13 at 16:24
  • You get a stack trace if you want one, by catching the exception. You also have a log with reams of information in it – DataNucleus Nov 14 '13 at 16:28
  • The class "com.appspot.blabla.model.entities.DataUrls" is required to be persistable yet no Meta-Data/Annotations can be found for this class. Please check that the Meta-Data/annotations is defined in a valid file location. – J.Pip Nov 14 '13 at 20:05
  • so check the enhancement of the class by decompiling it, and check what is in the classpath; the log tells you about what is in what location. Decompilation via http://stackoverflow.com/questions/272535/how-do-i-decompile-java-class-files – DataNucleus Nov 15 '13 at 08:10

1 Answers1

1

I ran across this same issue today. I figured once I found a solution I would share.

My code was pretty much identical with yours except for a different use case (obviously). The problem was that I had forgotten to update my persistence.xml file with the location of the new entity I was trying to persist. Hence the reason DN didn't recognize the class as an entity.

Whiteout
  • 31
  • 3