views:

85

answers:

3

I have the following class :

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.*;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class PayPal_Message
{
  @PrimaryKey
  @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Long id;
  @Persistent
  private Text content;
  @Persistent
  private String time;

  public PayPal_Message(Text content,String time)
  {
    this.content=content;
    this.time=time;
  }

  public Long getId() { return id; }
  public Text getContent() { return content; }
  public String getTime() { return time; }
  public void setContent(Text content) { this.content=content; }
  public void setTime(String time) { this.time=time; }
}

It used to be in a package, and works fine, now I put all classes in the default package, which caused me this error :

org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The class "The class "PayPal_Message" 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." 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 for the class is not found. NestedThrowables: org.datanucleus.exceptions.ClassNotPersistableException: The class "PayPal_Message" 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.

What should I do to fix it ?

A: 

I've gotten these exceptions sometimes for no discernible reason.

Adding a space somewhere in the persistent class and rebuilding has fixed it for me in the past. No idea why it happens or why rebuilding fixes it, but worth a shot at least.

Jason Hall
A: 

I ended up putting them back to the package, and it works fine now.

Frank
A: 

Explanation: classes in the default package are not visible/importable by classes inside a package.

Try the following examples:

public class Entity {}

(thus without package!) and

package persistence;

public class EntityManager {
    public static void main(String... args) {
        Entity entity = new Entity();
    }
}

Does it work? No? How would you ever import it? That's the problem which happens behind the scenes!

BalusC
But I put "ALL" calsses in that project in the default package, why couldn't it work ?
Frank
Because the persistence API which you're using (Datanucleus in this case) isn't using the default package. It's not literally the above code, but that's what happens "behind the scenes". You cannot access classes in the default package from other packages on.
BalusC
OK, that makes sense, thanks.
Frank