Problem saving list <String> via JPA?

I've already seen

How to save a property of type List <String> in JPA?

and

Match a list of strings with JPA / Hibernate annotations

==================================================== =============================

I'm trying to save

List<String> 

through JPA. I found out that JPA 1.0 has no way to preserve the collection of non-entities, but JPA 2.0 included the @CollectionOfElements annotation.

First off, I'm not sure which version of JPA 2.0 to use. I used toplink-essentials before, but it has no @CollectionOfElements annotation.

I downloaded eclipse-link but did not find jar files in it.

So my question is what implementation of JPA 2.0 to use that provides jar files so that I can include these banks in my project, as was done for important links.

+4
source share
3 answers

First off, I'm not sure which version of JPA 2.0 to use. I used toplink-essentials before, but it has no @CollectionOfElements annotation.

TopLink-Essential is not a JPA 2.0 implementation. And as James noted, note that the JPA 2.0 annotation @ElementCollection , @CollectionOfElements is a Hibernate annotation that is now deprecated in favor of the JPA annotation.

I downloaded eclipse-link but did not find jar files in it.

What did you download? EclipseLink 2.1.1 Installer Zip (28 MB), which you can get from the download page , contains an all-in-one jar in the jlib directory.

So my question is what implementation of JPA 2.0 to use that provides jar files so that I can include these banks in my project, as was done for important links.

Any of them. I personally used Hibernate 3.5.x or EcliseLink 2.x, which you can get accordingly from

Link

  • JPA 2.0 Specification
    • Section 11.1.12 "Annotation of the ElementCollection"
+4
source

Note that JPA 2.0 defines @ElementCollection, not @CollectionOfElements. It can be used to store the list. @CollectionOfElements is an extension of Hibernate.

In TopLink Essentials (JPA 1.0), you can still match this, but you will need to use the DescriptorCustomizer to define DirectCollectionMapping in your code.

In EclipseLink 1.0, it was defined as @BasicCollection, and in JPA 2.0 and EclipseLink> = 1.2 it was defined as @ElemenetCollection.

+4
source

Just use ArrayList instead of List. I tried

 @Entity public class Orar implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private ArrayList<String> lectii; 

and it works;)

+1
source

All Articles