简体   繁体   English

一个实体上有两个关系

[英]two relations on one entity, jhipster

i have this model, and i trying to create the model on jhipster 4 and JDLStudio to generate entityes. 我有这个模型,我试图在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

but when i run the app, i have this error 但是当我运行该应用程序时,出现此错误

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)

and my Entity Encargo is: 而我的实体Encargo是:

private static final long serialVersionUID = 1L; 私有静态最终长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<>();

and my changelog is: 我的变更日志是:

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

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

the attributes are: 属性是:

@ManyToOne
private ValorDominio tipoEvento;

@ManyToOne
private ValorDominio estado;

I await your answers. 我等待你的回答。

the error is, that the proper way of mapping 1:n is by giving the many-side the "entity_id" column. 错误是,映射1 :: n的正确方法是通过给多端提供“ entity_id”列。 Your JDL points a unidirectional relationship from ValorDomino to Encargo , while ValorDomino is the owning side. 您的JDL指出了从ValorDominoEncargo的单向关系,而ValorDomino是拥有者。 So consequently Encargo has no view of the referencing entity and so far has no way to distinguish it. 因此, Encargo因此没有引用实体的视图,并且到目前为止还没有办法区分它。 This leads to the error you got. 这导致您得到错误。

Try to move the relation to an:1 definition: 尝试将关系移至an:1定义:

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

so the join columns to valor domino will be different on encargo 因此,与envalgo上的valor domino的连接列将有所不同

thanks for your answer, im trying your method but not working, 感谢您的回答,即时通讯正在尝试您的方法,但无法正常工作,

i trying with this and work fine, but now i have to change the get method on view to charge diferent data on diferent selectItems 我尝试与此并工作正常,但现在我不得不更改视图上的get方法以对不同的selectItems收取不同的数据

ValorDominio{tipoEvento(descripcion)} to Encargo{tipoEcargo(descripcion)},
ValorDominio{estado(descripcion)} to Encargo{estado(descripcion)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM