Berkeley DB 中的突变错误
Posted
技术标签:
【中文标题】Berkeley DB 中的突变错误【英文标题】:Mutation error in Berkeley DB 【发布时间】:2009-05-23 17:16:49 【问题描述】:我正在使用 Berkely DB,但出现一个错误,提示缺少突变。这是什么意思?
Exception: com.sleepycat.persist.evolve.IncompatibleClassException: Mutation is missing to evolve class: TopMoveDAO.TopMoveClass version: 0 Error: java.lang.ClassNotFoundException: TopMoveDAO.TopMoveClasscom.sleepycat.persist.evolve.IncompatibleClassException: Mutation is missing to evolve class: TopMoveDAO.TopMoveClass version: 0 Error: java.lang.ClassNotFoundException: TopMoveDAO.TopMoveClass
在 com.sleepycat.persist.impl.PersistCatalog.(PersistCatalog.java:365) 在 com.sleepycat.persist.impl.Store.(Store.java:180) 在 com.sleepycat.persist.EntityStore.(EntityStore.java:165) 在 TopMoveDAO.TopMovePut.setup(TopMovePut.java:40) 在 TopMoveDAO.TopMovePut.run(TopMovePut.java:59) 在 TopMoveDAO.TopMovePut.main(TopMovePut.java:84)
package TopMoveDAO;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.persist.EntityStore;
import com.sleepycat.persist.StoreConfig;
public class TopMovePut
//private static File envHome = new File("C:/dev/je-3.3.75/");
private static File envHome = new File("C:/dev/db/berkeley");
private Environment envmnt;
private EntityStore store;
private TopMoveDA sda;
//Next we create a method that simply opens our database environment and entity store for us.
// The setup() method opens the environment and store
// for us.
public void setup()
throws DatabaseException
EnvironmentConfig envConfig = new EnvironmentConfig();
StoreConfig storeConfig = new StoreConfig();
envConfig.setAllowCreate(true);
storeConfig.setAllowCreate(true);
// Open the environment and entity store
envmnt = new Environment(envHome, envConfig);
store = new EntityStore(envmnt, "EntityStore", storeConfig);
//We also need a method to close our environment and store.
// Close our environment and store.
public void shutdown()
throws DatabaseException
store.close();
envmnt.close();
//Populate the entity store
private void run()
throws DatabaseException
setup();
// Open the data accessor. This is used to store
// persistent objects.
sda = new TopMoveDA(store);
// Instantiate and store some entity classes
PriceElement pe1 = new PriceElement();
pe1.setSecCode("UNO");
pe1.setLastPrice(1);
sda.pIdx.put(pe1);
shutdown();
//main
public static void main(String args[])
//SimpleStorePut ssp = new SimpleStorePut();
TopMovePut tmp = new TopMovePut();
try
//ssp.run();
tmp.run();
catch (DatabaseException dbe)
System.err.println("TopMovePut: " + dbe.toString());
dbe.printStackTrace();
catch (Exception e)
System.out.println("Exception: " + e.toString());
e.printStackTrace();
System.out.println("All done - TopMovePut.");
【问题讨论】:
【参考方案1】:您必须编写一个突变来发展您的数据库。删除数据库并不能解决问题,只能绕过它(如果您还没有部署到生产环境,这很好,但如果您不想丢失现有数据,请编写突变。)
对持久实体的某些更改由 Berkley db 自动处理,例如添加字段。涉及删除数据或重命名字段的通常需要您编写显式突变。当您开始使用突变时,您还必须使用突变将引用的版本号注释您的实体 - 即使自动处理突变,您也必须增加版本号。当您进行重大的结构更改(例如使用不同的主键)时,您将不得不进行整个存储转换。
在复制环境中演进数据库时要小心。我强烈建议阅读以下内容:
Package com.sleepycat.persist.evolve (Oracle - Berkeley DB Java Edition API)
【讨论】:
链接:oracle.com/technology/documentation/berkeley-db/je/java/com/… 不可用。新的是docs.oracle.com/cd/E17277_02/html/java/com/sleepycat/persist/…【参考方案2】:您必须每次都删除现有的数据库。
【讨论】:
以上是关于Berkeley DB 中的突变错误的主要内容,如果未能解决你的问题,请参考以下文章