我正在将JPA用于java类,并且无法将持久性XML文件放在应该存在的位置.
我使用的IDE是Eclipse Helios.Eclipselink jar文件已下载并添加到我的JRE系统库和所有文件中.在收到以下错误后,我用标签写了persistence.xml:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named customers
Run Code Online (Sandbox Code Playgroud)
提供者标签:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
Run Code Online (Sandbox Code Playgroud)
该程序仍然没有运行所以我想知道我应该在哪里放置persistence.xml(即src/main/resources,或lib/META-INF ......等)
在重复的情况下,ObjectMapper 默认只保留其中一个元素作为键。即,最后一个元素将始终是存储的元素。例如:
{“名称”:“xyz”,“名称”:“abc”}
如果我们在上面的树上使用 ObjectMapper readTree,它将深入到:
--> ObjectMapper.readTree(<json-input>)
--> ObjectMapper._readMapAndClose
--> BaseNodeDeseralizer.deserializeObject
--> JsonNode old = node.replace(key, value); // replaces a key in case of duplicates
Run Code Online (Sandbox Code Playgroud)
上面的代码会将 "name":"xyz" 添加到树中,然后在第二次运行时,将其替换为 "name":"abc"。
有配置选项会导致 ObjectMapper 在重复的情况下失败/吐出错误。例如:
mapper.enable(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS);
mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY);
Run Code Online (Sandbox Code Playgroud)
但我找不到允许重复的配置选项。
我已经尝试覆盖 deserializeObject 方法来不进行替换。但这似乎是不明智的,因为我的覆盖方法将“脱离”库的方法,我将无法获取未来的更新/修复。
我的问题是:ObjectMapper 是否允许保留重复键(考虑到它使用的数据结构)?如果是这样,如何?