我正在尝试制作datanucleus,使用Mongodb(使用JDO)。成功后
mvn clean compile
mvn exec:java
当我第一次跑步时,
失败了caused by: org.datanucleus.exceptions.NucleusUserException: Found Meta-Data for class com.samples.jdo.mongodb.Account but this class is either not enhanced or you have multiple copies of jdo-api.jar in your CLASSPATH!! Make sure all persistable classes are enhanced before running DataNucleus and/or the CLASSPATH is correct.
但如果我再次运行它工作正常,我也可以看到数据在mongodb中持续存在。
// Create a PersistenceManagerFactory for this datastore
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("datanucleus.properties", this.getClass().getClassLoader());
JDOMetadata jdomd = pmf.newMetadata();
PackageMetadata pmd = jdomd.newPackageMetadata("com.samples.jdo.mongodb");
ClassMetadata cmd1 = pmd.newClassMetadata(Account.class);
cmd1.setTable("Account").setIdentityType(javax.jdo.annotations.IdentityType.DATASTORE);
cmd1.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_CAPABLE);
ClassMetadata cmd2 = pmd.newClassMetadata(Login.class);
cmd2.setTable("LOGIN").setIdentityType(javax.jdo.annotations.IdentityType.DATASTORE);
cmd2.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_CAPABLE);
PersistenceManager pm = pmf.getPersistenceManager();
Account acct = new Account("firstname","lastname", 3);
Login login = new Login("flastname", "xxxx");
acct.setLogin(login);
final JDOEnhancer enhancer = JDOHelper.getEnhancer();
enhancer.setVerbose(true);
enhancer.registerMetadata(jdomd);
enhancer.setClassLoader(this.getClass().getClassLoader());
String[] classes = {"com.samples.jdo.mongodb.Account","com.samples.jdo.mongodb.Login" };
enhancer.addClasses(classes);
enhancer.enhance();
pmf.registerMetadata(jdomd);
pm.makePersistent(acct);
任何想法?
由于