【发布时间】:2017-04-27 22:14:48
【问题描述】:
我对 JHipster 比较陌生。
此应用程序是使用 JHipster 3.12.1 生成的
我有以下 jdl 文件:
entity Country {
countryCd String minlength(2) maxlength(2) required,
countryNm String maxlength(64) required
}
entity State{
stateCd String minlength(2) maxlength(2) required,
stateNm String maxlength(40) ,
stateTypeCd String maxlength(1) required
}
entity ZipCode{
zipCd String maxlength(20) required
}
entity ZipCodeGeoBrg{
countryCd String minlength(2) maxlength(2) required,
zipCd String maxlength(20) required,
cityNm String maxlength(100) required,
stateCd String minlength(2) maxlength(2) required,
countyNm String maxlength(100) ,
countyCd String maxlength(20) ,
communityNm String maxlength(100) ,
communityCd String maxlength(20) ,
latitudeNum BigDecimal ,
longitudeNum BigDecimal,
accuracyNum Integer
}
relationship OneToMany {
ZipCode{zipCodeGeoBrg} to ZipCodeGeoBrg{zipCode(zipCd)},
Country{zipCodeGeoBrg(countryCd)} to ZipCodeGeoBrg{country(countryCd)},
State{zipCodeGeoBrg(stateCd)} to ZipCodeGeoBrg{state(stateCd)}
}
dto * with mapstruct
service all with serviceImpl
search ZipCodeGeoBrg with elasticsearch
jdl 文档说明:
默认情况下,连接是通过 id 字段完成的……但是如果您希望连接由另一个字段完成,那么您可以执行以下操作:
实体 A { 名称 字符串必填 } 实体B
关系 OneToOne { A{b} 到 B{a(name)} }
生成的类 (ZipCodeGeoBrg) 具有以下属性:
@ManyToOne
private ZipCode zipCode;
@ManyToOne
private Country country;
@ManyToOne
private State state;
生成了我的实体类,但所有连接都在 id 列上,而不是在命名列上(例如 countryCd)。我期待的是这样的:
@ManyToOne
@JoinColumn( name = "COUNTRY_CD" )
private Country country;
@ManyToOne
@JoinColumn( name = "STATE_CD" )
private State state;
@ManyToOne
@JoinColumn( name = "ZIP_CD" )
private ZipCode zipCode;
我也试过这样的jdl:
relationship OneToMany {
ZipCode to ZipCodeGeoBrg{zipCode(zipCd)},
Country to ZipCodeGeoBrg{country(countryCd)},
State to ZipCodeGeoBrg{state(stateCd)}
}
得到了同样的结果。
这是一个现有的数据库。 DBA 愿意更新表并添加一个 ID 列,但不愿意重做所有关系(例如 zip_cd 是与 ZipCode ZipCodeGeoBrg 相关的现有列,这不会改变)。所以我必须使这些与不是 ID 的列一起工作。我知道我可以在生成后手动更新实体,但我还有 20 个表要做,我宁愿让工具为我做。
我错过了什么?
【问题讨论】:
标签: jhipster