Hello,
I'm trying to map an existing schema with entity beans and I have some troubles with the MapKey annotation due to column not having same name as property.
Map in owning class:
Code:
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="`cardId`")
@MapKey(name="subProdType")
public Map<String, CardState> getStates() {
return states;
}
Class thats ends up in the map:
Code:
public class CardState {
private String subProdType;
...
@Column(name="`subProdType`")
public String getSubProdType() {
return subProdType;
}
public void setSubProdType(String subProdType) {
this.subProdType = subProdType;
}
...
When trying to get the state, the generated query looks for a column named after the property name which doesn't work since the column has case sensitive name:
select states0_."cardId" as cardId8_1_,
states0_."stateId" as stateId1_1_,
states0_.subProdType as formula15_1_,
states0_."stateId" as stateId1_198_0_,
states0_."state" as state2_198_0_,
states0_."subProdType" as subProdT3_198_0_,
...
from "cardState" states0_
where states0_."cardId"=?
Any idea how I could bypass this little annoyance?
I know alternatives to usage of maps exist but cascading and automatic loading is very convenient here.
I was also curious about why stateId appears twice in the query as it doesn't when loading a CardState entity directly.
Thanks for your help,
Eric.