Re: How to persist a property of type List<String>in JPA

Discussion in 'Java' started by Lew, Nov 13, 2008.

  1. Lew

    Lew Guest

    On Nov 13, 10:40 am, Andrea Francia
    <_FROM_HERE_ohohohioquestoèdatogliereohohoho_TO_HERE.it>
    wrote:
    > What is the smartest way to get an entity with a field of type
    > List<String> get persisted?
    >
    > Command.java
    > ---------------------------------------------------
    > package persistlistofstring;
    >
    > import java.io.Serializable;
    > import java.util.ArrayList;
    > import java.util.List;
    > import javax.persistence.Basic;
    > import javax.persistence.Entity;
    > import javax.persistence.EntityManager;
    > import javax.persistence.GeneratedValue;
    > import javax.persistence.GenerationType;
    > import javax.persistence.Id;
    > import javax.persistence.Persistence;
    >
    > @Entity
    > public class Command implements Serializable {
    >
    >      @Id
    >      @GeneratedValue(strategy = GenerationType.AUTO)
    >      Long id;
    >      @Basic
    >      List<String> arguments = new ArrayList<String>();


    You might have some luck if you declare 'arguments' as 'ArrayList'
    instead of 'List', since 'ArrayList' implements 'Serializable'.

    You should still have a table design, though.

    Read this chapter:
    <http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpy.html>

    It's what inspired me to suggest 'ArrayList'.

    Also, different JPA implementations (TopLink, Hibernate, OpenJPA)
    extend the JPA standard in different ways, sometimes allowing things
    not strictly permitted by vanilla JPA.

    --
    Lew
    Lew, Nov 13, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Umut Tezduyar
    Replies:
    0
    Views:
    431
    Umut Tezduyar
    Nov 29, 2005
  2. Umut Tezduyar
    Replies:
    0
    Views:
    421
    Umut Tezduyar
    Dec 2, 2005
  3. redbull
    Replies:
    2
    Views:
    733
    Kenneth P. Turvey
    Oct 31, 2007
  4. Lew
    Replies:
    3
    Views:
    1,852
  5. john

    jpa persist , merge ?

    john, Dec 24, 2010, in forum: Java
    Replies:
    0
    Views:
    928
Loading...

Share This Page