如何在Play Framework 2.3.8中保存一组字符串? [英] How to persist a collection of Strings in Play Framework 2.3.8?
问题描述
我有这样的模型:
import play.db.ebean.Model;
import javax.persistence。*;
import java.util。*;
@Entity
公共类翻译扩展模型{
@Id
public Long id;
@ElementCollection
public Set< String> languages = new HashSet<>();
}
当我编译并运行时,没有语言在数据库演变中
。数据库是Heroku上的PostgreSQL 9.3.6。
我尝试了 List
和 ArrayList
,但这没有帮助。
如何在Play Framework 2.3.8中保存一个字符串集合?
目前还不支持EBean。正如您所知,Play Framework 2。 X附带 EBean 作为其ORM框架。 EBean显然实现了JPA规范的一个子集,并且似乎缺少一些JPA2特性。
然而,GitHub有一个针对 @ElementCollection
功能,它似乎也已经实现,但没有发布:
https://github.com/ebean-orm/avaje-ebeanorm/issues/115
所以,无聊的答案是等到Play带有一个支持注释的ORM实现。另一种方法是使用支持 @ElementCollection
的JPA提供程序修补(如果可能)您的Play分发。
I have such model:
import play.db.ebean.Model;
import javax.persistence.*;
import java.util.*;
@Entity
public class Translation extends Model {
@Id
public Long id;
@ElementCollection
public Set<String> languages = new HashSet<>();
}
When I compile and run, there are no languages
in the database evolution. The database is PostgreSQL 9.3.6 on Heroku.
I tried with List
and ArrayList
, but this didn't help.
How to persist a collection of Strings in Play Framework 2.3.8?
It is not yet supported by EBean.
As you know, Play Framework 2.X ships with EBean as its ORM framework. EBean apparently implements a subset of the JPA specification, and seems to be missing some of the JPA2 features.
There is however an open enhancement request on GitHub for the @ElementCollection
feature, which also seems to already been implemented, but not released:
https://github.com/ebean-orm/avaje-ebeanorm/issues/115
So, the boring answer is to wait until Play ships with an ORM implementation which supports the annotation. The other option is to patch (if possible) your Play distribution with a JPA provider that supports @ElementCollection
.
这篇关于如何在Play Framework 2.3.8中保存一组字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!