我已经看过了
How to persist a property of type List<String> in JPA?
和
Map a list of strings with JPA/Hibernate annotations
============================================= ==============================
我正在努力挽救
List<String>
通过 JPA。我开始知道 JPA 1.0 没有任何方法来持久保存非实体类的集合,但 JPA 2.0 包含了 @CollectionOfElements
注释。
首先,我不确定要使用哪个 JPA 2.0 实现。早些时候我使用的是 toplink-essentials,但它没有 @CollectionOfElements
注释。
我下载了 eclipse-link 但没有在其中找到任何 jar 文件。
所以我的问题是要使用哪个 JPA 2.0 实现来提供 jar 文件,以便我可以将这些 jar 包含在我的项目中,就像我对 toplink-essentials 所做的那样。
最佳答案
First, I am not sure which JPA 2.0 implementation to use. Earlier I was using toplink-essentials but it doesn't have @CollectionOfElements annotation.
TopLink-Essential 不是 JPA 2.0 实现。正如 James 所指出的,请注意 JPA 2.0 注释是 @ElementCollection
,@CollectionOfElements
是 Hibernate 特定的注释,现在已弃用,取而代之的是 JPA 注释。
I downloaded eclipse-link but didn't find any jar files inside it.
你下载了什么?您可以从 download page 获得的 EclipseLink 2.1.1 安装程序 Zip (28 MB)在 jlib 目录中包含一个一体化的 jar。
So my question is to which JPA 2.0 implementation to use which provides jar files so that I can include those jars in my project as I have done for toplink-essentials.
其中任何一个。我个人会使用 Hibernate 3.5.x 或 EcliseLink 2.x,您可以分别从
- https://sourceforge.net/projects/hibernate/files/hibernate3/3.5.5-Final
- http://www.eclipse.org/eclipselink/downloads/
引用
- JPA 2.0 规范
- 第 11.1.12 节“ElementCollection 注释”
关于java - 通过 JPA 保存 List<String> 时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3674191/