我已经看过了
How to persist a property of type List in JPA?
和
Map a list of strings with JPA/Hibernate annotations
=============================================================================
我在试着节省
List<String>通过JPA。我知道JPA1.0没有任何方法来持久化非实体类的集合,但是JPA2.0已经包含了@CollectionOfElements注解。
首先,我不确定要使用哪个JPA2.0实现。之前我使用的是toplink-essentials,但它没有@CollectionOfElements注释。
我下载了eclipse-link,但没有发现里面有任何jar文件。
因此,我的问题是使用哪个JPA2.0实现来提供jar文件,这样我就可以像toplink-essentials那样将这些jar包含在我的项目中。
发布于 2010-09-09 19:04:50
首先,我不确定要使用哪个JPA2.0实现。之前我使用的是toplink-essentials,但它没有@CollectionOfElements注释。
TopLink-Essential不是JPA 2.0实现。正如James所指出的,请注意JPA2.0注释是@ElementCollection,@CollectionOfElements是Hibernate特定的注释,现在为了支持JPA注释,它已被弃用。
我下载了eclipse-link,但是没有找到任何jar文件。
你下载了什么?您可以从download page获得的jlib2.1.1安装程序压缩包(28MB)在EclipseLink目录中包含一个一体化jar。
所以我的问题是使用哪个JPA2.0实现来提供jar文件,这样我就可以在我的项目中包含这些jar,就像我对toplink-
所做的那样。
他们中的任何一个。我个人会使用Hibernate 3.5.x或EcliseLink 2.x,您可以分别从
参考文献
发布于 2010-09-09 21:23:08
请注意,JPA2.0定义的是@ElementCollection,而不是@CollectionOfElements。它可以用来存储列表。@CollectionOfElements是一个Hibernate扩展。
在TopLink软件包(JPA1.0)中,您仍然可以映射这一点,但需要使用DescriptorCustomizer在代码中定义DirectCollectionMapping。
在ElemenetCollection 1.0中,它被定义为@ EclipseLink,而在JPA2.0和EclipseLink >= 1.2中,它被定义为@ElemenetCollection。
发布于 2010-10-21 20:17:16
只需使用ArrayList而不是List。我试过
@Entity
public class Orar implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private ArrayList<String> lectii;它是有效的;)
https://stackoverflow.com/questions/3674191
复制相似问题