1

我们开始在我们的应用程序中试验 JaVers。我们希望跟踪用户下订单后的更改。因此,这是您的典型订单对象,其中包含主要订单对象、商品、商品选项等。大约有一半的时间运行测试程序,我们收到了这个异常:

130 [main] INFO org.javers.core.JaversBuilder - JaVers 实例已启动并准备就绪 线程“main”中的异常 JaversException:MANAGED_CLASS_MAPPING_ERROR 给定 javaClass 'class java.util.ArrayList' 映射到 ListType,org.javers 中的预期 ManagedType。 core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:149) 在 org.javers.core.metamodel.type.TypeMapper.getJaversManagedType(TypeMapper.java:132) 在 org.javers.core.metamodel.object.GlobalIdFactory。 createId(GlobalIdFactory.java:39) at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:24) at org.javers.core.graph.EdgeBuilder.asCdo(EdgeBuilder.java:39) at org.javers .core.graph.EdgeBuilder.buildSingleEdge(EdgeBuilder.java:32) 在 org.javers.core.graph.ObjectGraphBuilder.buildSingleEdges(ObjectGraphBuilder.java:81)在 org.javers.core.graph.ObjectGraphBuilder.buildEdges(ObjectGraphBuilder.java:71) 在 org.javers.core.graph.ObjectGraphBuilder.buildGraphFromCdo(ObjectGraphBuilder.java:59) 在 org.javers.core.graph.ObjectGraphBuilder .buildGraph(ObjectGraphBuilder.java:48) 在 org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39) 在 org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:109) 在 org. javers.core.diff.DiffFactory.compare(DiffFactory.java:64) 在 org.javers.core.JaversCore.compare(JaversCore.java:104)48) 在 org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:109) 在 org.javers.core.diff.DiffFactory 的 org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39) .compare(DiffFactory.java:64) 在 org.javers.core.JaversCore.compare(JaversCore.java:104)48) 在 org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:109) 在 org.javers.core.diff.DiffFactory 的 org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39) .compare(DiffFactory.java:64) 在 org.javers.core.JaversCore.compare(JaversCore.java:104)

我们只是重新运行程序,最终它就可以工作了。代码基本上是这样的。

// Original database object
OrderVO oldOrder = // load from database.

// Changed database object
OrderVO newOrder = // load from database.
// Change the email
newOrder.setEmail("test@test.com");
// Simulate changing quantity and item id on items
for (OrderItemVO OrderItemVO : newOrder.getItems()) {
  OrderItemVO.setMerchantItemId(OrderItemVO.getMerchantItemId() + "A");
  OrderItemVO.setQuantity(OrderItemVO.getQuantity().add(1));
}

// Remove the first item
OrderItemVO[] items = new OrderItemVO[newOrder.getItems().length - 1];
System.arraycopy(newOrder.getItems(), 1, items, 0, items.length);
newOrder.setItems(items);

// Run comparison
Javers javers = JaversBuilder.javers().withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
Diff diff = javers.compare(oldOrder, newOrder);
4

0 回答 0