java - 一个实体上的两个关系,jhipster

标签 java spring spring-boot jhipster

我有这个模型,我尝试在 jhipster 4 和 JDLStudio 上创建模型来生成实体。

entity Cliente{
    nombre String,
    apellido String,
    celular String,
    telefono String,
    email String,
    domicilio String,
    colegio String
}

entity Modelo{
    imagen ImageBlob,
    nombreModelo String,
    colorVestido String,
    observacion String
}

entity Medida{
    contornoBusto Double,
    anchoPecho Double,
    altoBusto Double,
    bajoBusto Double,
    alturaPinza Double,
    separacionBusto Double,
    talleDeltantero Double,
    talleEspalda Double,
    largoCorset Double,
    costado Double,
    hombro Double,
    anchoHombro Double,
    largoManga Double,
    sisa Double,
    cintura Double,
    anteCadera Double,
    cadera Double,
    largoPollera Double,
    fechaMedida LocalDate
}

entity Dominio{
    descripcion String
}
entity ValorDominio{
    descripcion String
}

entity Encargo{
    importeTotal Double,
    fechaEncargo LocalDate,
    fechaEntrega LocalDate,
    detalleVestido String
}

entity Pago{
    fechaPago LocalDate,
    importe Double,
    detalle String,
    numeroRecibo Integer
}


/**
  * Relacion Una empresa tiene uno o muchos usuarios
  */
relationship OneToMany {
    Cliente{modelo(nombre)} to Modelo,
    Cliente{medida(nombre)} to Medida,
    Cliente{encargo(nombre)} to Encargo,
    Encargo{pago} to Pago,
    Dominio{valorDominio(descripcion)} to ValorDominio,
    ValorDominio{tipoEvento(descripcion)} to Encargo,
    ValorDominio{estado(descripcion)} to Encargo
}

/**relationship OneToOne{
 *Cliente{user} to User{cliente}
 *}
 */


paginate Cliente with infinite-scroll

但是当我运行应用程序时,出现此错误

Migration failed for change set classpath:config/liquibase/changelog/20170313030953_added_entity_Encargo.xml::20170313030953-1::jhipster:
     Reason: liquibase.exception.DatabaseException: Duplicate column name 'valor_dominio_id' [Failed SQL: CREATE TABLE Clothes.encargo (id BIGINT AUTO_INCREMENT NOT NULL, importe_total DOUBLE NULL, fecha_encargo date NULL, fecha_entrega date NULL, detalle_vestido VARCHAR(255) NULL, cliente_id BIGINT NULL, valor_dominio_id BIGINT NULL, valor_dominio_id BIGINT NULL, CONSTRAINT PK_ENCARGO PRIMARY KEY (id))]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619)

我的实体 Encargo 是:

私有(private)静态最终长serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "importe_total")
private Double importeTotal;

@Column(name = "fecha_encargo")
private LocalDate fechaEncargo;

@Column(name = "fecha_entrega")
private LocalDate fechaEntrega;

@Column(name = "detalle_vestido")
private String detalleVestido;

@ManyToOne
private Cliente cliente;

@ManyToOne
private ValorDominio tipoEvento;

@ManyToOne
private ValorDominio estado;

@OneToMany(mappedBy = "encargo")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Pago> pagos = new HashSet<>();

我的变更日志是:

<column name="valor_dominio_id" type="bigint" >
     <constraints nullable="true" />
</column>

<column name="valor_dominio_id" type="bigint">
     <constraints nullable="true" />
</column>

属性是:

@ManyToOne
private ValorDominio tipoEvento;

@ManyToOne
private ValorDominio estado;

我等待您的答复。

最佳答案

错误在于,映射 1:n 的正确方法是为多方提供“entity_id”列。您的 JDL 指向从 ValorDominoEncargo 的单向关系,而 ValorDomino 是拥有方。因此,Encargo 无法查看引用实体,并且到目前为止还无法区分它。这会导致您遇到错误。

尝试将关系转移到 n:1 定义:

relationshop ManyToOne {
    Encargo{tipoEventoEncargo} to ValorDominio,
    Encargo{estadoEncargo} to ValorDominio
}

因此 valor domino 的连接列在 encargo 上会有所不同

关于java - 一个实体上的两个关系,jhipster,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42756209/

相关文章:

mongodb - Spring MongoDB 聚合 DBRef

java - 无法使用 Thymeleaf 渲染对象 : Property or field cannot be found on object of type 'org.parse4j.ParseObject' - maybe not public?

java - 如何让一个被 ControllerAdvice 注解的类来处理不同类型的异常?

java - 比较两个字符串时出现空指针异常

java - 如何使用 Pooled Spring beans 而不是 Singleton 的?

spring - Spring Cloud OpenFeign无法创建动态查询参数

java - 如何使用 Java 在 CKFinder 2.2 中更改文件上传 URL

java - 保留具有双向关系的嵌套实体(一对多)

java - 如何从 RxJava Flowable 更新 JavaFX 进度条?

java - 为Hadoop设置我的JAVA_HOME变量