我正在接收JSON请求的值的简单列表部分,我希望将其保存为逗号分隔值。尝试使用以下,但它没有奏效。JPA:将值列表保存为逗号分隔值
@Column(nullable = true)
@GeneratedValue(strategy = GenerationType.AUTO)
private ArrayList<String> services = new ArrayList<String>() ;
和
@Column(nullable = true)
@ElementCollection(targetClass = String.class)
private List<String> services = new ArrayList<String>() ;
@ElementCollection
抛出异常说table services does not exist
。
ElementCollection仍然存储在单独的表中收集,每行一个字符串。我不知道你在哪里读取它将元素存储为逗号分隔值。您需要一个自定义类型或转换的JPA属性。此外,使用GeneratedValue注释字符串列表没有任何意义。 –
您可以尝试使用AttributeConverters作为替代方法:http://hantsy.blogspot.com/2013/12/jpa-21-attribute-converter.html – Ish