【发布时间】:2018-03-18 02:16:33
【问题描述】:
我刚刚开始学习如何使用 Hibernate,但我无法弄清楚在引用接口时如何正确注释列表。
这是我的情况,我有一个像这样实现 MarketOrder 的类 MarketOrderImpl...
@Entity
public final class MarketOrderImpl implements MarketOrder {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
private OrderType type;
private BigDecimal price;
private BigDecimal quantity;
private BigDecimal total;
public MarketOrderImpl(OrderType type, BigDecimal price, BigDecimal
quantity, BigDecimal total) {
this.type = type;
this.price = price;
this.quantity = quantity;
this.total = total;
}
我有一个 MarketOrderBookImpl,它有两个列表,我无法毫无例外地注释(私有列表 sellOrders 和私有列表 buyOrders)
@Entity
public final class MarketOrderBookImpl implements MarketOrderBook {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String marketId;
@OneToMany @JoinTable(name="marketorderimpl")
@MapKeyColumn(name="id")
private List<MarketOrder> sellOrders;
@OneToMany @JoinTable(name="marketorderimpl")
@MapKeyColumn(name="id")
private List<MarketOrder> buyOrders;
public MarketOrderBookImpl(String marketId, List<MarketOrder>
sellOrders, List<MarketOrder> buyOrders) {
this.marketId = marketId;
this.sellOrders = sellOrders;
this.buyOrders = buyOrders;
}
这是我的例外...
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class:br.com.codefleck.tradebot.exchanges.trading.api.impl.MarketOrderBookImpl.sellOrders[br.com.codefleck.tradebot.tradingapi.MarketOrder]at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1136) at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:792)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:727)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ... 66 more
提前感谢您的帮助!
【问题讨论】:
-
@Mohammad 我不同意,这是一个不同的问题,因为它是关于不同实体之间的映射和多样性。
标签: java hibernate jpa annotations jpa-2.1