【问题标题】:jhipster: add @ElementCollection to existing entityjhipster:将@ElementCollection 添加到现有实体
【发布时间】:2015-12-12 17:06:59
【问题描述】:

我正在尝试手动使用 @ElementCollection,因为 jhipster 文档的关系部分中没有提到它。我更改了 java 类,尝试通过 mvn liquibase:diff 生成具有更改的 liquibase 文件,然后在我的 entity.json 中包含一个关系

 "relationships": [

        {
            "relationshipId": 1,
            "relationshipName": "contato_telefone",
            "otherEntityName": "telefone",
            "relationshipType": "one-to-many",
            "otherEntityField": "telefone",
            "ownerSide": true
        }

实体类

 @ElementCollection
    @CollectionTable(name = "contato_telefone", joinColumns = @JoinColumn(name = "id_contato"))
    @Column(name = "telefone")
    private List<String> telefone;

当我尝试运行应用程序时,我得到了一个 LazyInitiationException 并且没有创建关系表 contato_telefone。我错过了什么吗?我需要做什么来解决这个问题?

【问题讨论】:

    标签: java jpa jhipster


    【解决方案1】:

    JHipster 仅支持实体之间的关系,因此将您的关系添加到您的 entity.json 不起作用,应该将其删除。

    因此,要让它发挥作用,您只能靠自己,但 JHipster 不应该妨碍您。 你必须创建一个 Liquibase 迁移文件来创建你的表并从 master.xml 中引用这个文件,我猜这就是你所做的。

    LazyInitializationException 是一个常见的错误,看看LazyInitializationException when using ElementCollection in Play framework

    【讨论】:

      猜你喜欢
      • 2018-06-17
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      相关资源
      最近更新 更多