私は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);
何か案は?
ありがとう