【问题标题】:@ElementCollection : Use the owning entity table of the collection@ElementCollection :使用集合的拥有实体表
【发布时间】:2017-09-15 15:39:39
【问题描述】:

我有这个实体:

@Entity
@Table( name = "Group" )
public class Group implements Serializable {

@Id
private Long id;

@ElementCollection
@CollectionTable( name = "Group" )//this sends an exception
@Column( name = "places_availables" )
private List<Integer>       places = new ArrayList<Integer>();
}

我想知道是否有办法阻止 Hibernate 生成新表并在 Group 表中添加新列。 非常感谢

【问题讨论】:

  • 这将如何运作?一个组可以有很多地方。您如何设想将这些多个关联存储在组表中?
  • 在我看来,我认为这个 List 可以像这样存储在一行中:[1,2,4,5,6,7] 但似乎并非如此。
  • 所以没有办法。甚至将列定义为 blob 或其他内容。
  • 可能有一种方法,但是它违背了数据库设计的基本原理。您可能可以使用 JPA 2 转换器从 String List 来回转换

标签: hibernate spring-data entity jpa-2.0


【解决方案1】:

我回来了一个解决方案,我在保存之前将列表转换为字符串,并在从数据库中检索它时进行反向操作。

【讨论】:

    猜你喜欢
    • 2019-07-05
    • 2014-10-02
    • 2010-12-05
    • 2012-03-14
    • 2011-08-01
    • 2021-01-09
    • 2021-07-18
    • 1970-01-01
    相关资源
    最近更新 更多