class A
{
...
@OneToMany()
@JoinColumn(name="A_ID")
/* B_ID should be the key in this map */
private Map map = new HashMap();
}
class B
{
@EmbeddedId
private CompoundId id;
}
@Embeddable
class CompoundId
{
@Column(name = "A_ID")
String aId;
@Column(name = "B_ID")
long bId
}
我也试过
@OneToMany()
@JoinColumn(name="A_ID", insertable=false, updatable=false)
@MapKeyColumn(name="B_ID")
private Map map = new HashMap();
Caused by: java.sql.SQLException: ORA-00904: "B1_"."ID": invalid identifier
没有运气
在映射XML中它看起来像这样
<map name="map" inverse="true" cascade="all-delete-orphan" lazy="false">
<key>
<column name="A_ID" />
</key>
<map-key type="long" column="B_ID"/>
<one-to-many class="B" />
</map>
hibernate 3.2.7.ga和注释3.4.0.GA
thx!
答案 0 :(得分:1)
尝试一下:
@Entity
public class A {
@Id private String id;
@OneToMany()
@MapKeyColumn(name="B_ID")
private Map<String, Long> associatedBs;
// ...
}
我可能会遗漏一些东西,但@MapKeyColumn
是重要的部分。我之前已成功完成此操作,但我的代码在办公室,所以我无法仔细检查它。
答案 1 :(得分:1)
@OneToMany()
@JoinColumn(name="A_ID", insertable=false, updatable=false)
@MapKeyColumn(name="B_ID")
private Map map = new HashMap();
确实有效,问题似乎出现在B类
的复合id的映射中干杯