I'm trying to annotate a Map<String, Child> from Parent:
Code:
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id", nullable = false)
public Map<String, Child> getChildren() {}
child:
Code:
@ManyToOne
@JoinColumn(name = "parent_id", nullable = false, insertable = false, updatable = false)
public Parent getParent() {}
I have the parent.hbm.xml, from which the relevant mapping:
Code:
<map name="children" table="child">
<key column="parent_id" foreign-key="child_parent_fk"/>
<map-key type="string"
formula="(select 3rd.name from thirdtable 3rd where 3rd.id = child_3rd_id)"/>
<one-to-many class="Child"/>
</map>
So. How do I annotate this? The aforementioned annotations do not work, they cause an exception:
Code:
org.hibernate.HibernateException: null index column for collection: Parent.children
Please note I have obfuscated the code and am simply trying to port the hbm.xml to annotations. I have no idea why the key is the name field from an associated third table/entity, but that's how it's been designed and I cannot change it.