[英]How to use Hibernate annotations
I have following tables in in DB: Tables 我已经在DB下表: 表
and want to have hibernate @Entity ExchangeRates like followng POJO: 并想让@Entity ExchangeRates休眠,例如followng POJO:
class ExchangeRates{
List<Currency> currencies;
}
class Currency{
Long Id;
String name;
List<Rate> exchangeRates;
}
class Rate{
Currency currency;
BibDecimal rate;
}
can any advice me how to do this with hibernate annotations? 可以建议我如何使用休眠注释执行此操作吗?
If you have two Entities
with a ManyToMany
relationship you will have a JoinTable that references both. 如果您有两个具有ManyToMany
关系的Entities
,则将有一个引用两者的JoinTable。
The Table would eg look like this: 该表例如如下所示:
Name: EX_CUR
Column 1:CUR_ID
Column 2:EX_ID
And the Entities like this: 和这样的实体:
@Entity
@Table(name="currencies_fixed_exchange_rates")
class ExchangeRates{
@Id
Long id;
@ManyToMany
@JoinTable(
name="EX_CUR",
joinColumns=@JoinColumn(name="CUR_ID",
referencedColumnName="ID"),
inverseJoinColumns=@JoinColumn(name="EX_ID",
referencedColumnName="ID"))
List<Currency> currencies;
}
@Entity
@Table(name="currencies")
class Currency{
@Id
Long Id;
@Column
String name;
@ManyToMany(mappedBy="currencies")
List<Rate> exchangeRates;
}
@Entity
@Table
class Rate{
@Id
Long id;
@OneToOne
Currency currency;
@Column
BigDecimal rate;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.