Hi,
I have a small problem when mapping a Map.
I can't force Hibernate to rename the foreign key column which is used as the key for the map.
Here's the code :
Code:
// ...
@CollectionOfElements
@JoinTable(name = "ISSUE_CONTENTS", joinColumns = @JoinColumn(name = "ISSUE_ID_FK"))
@Column(name = "CONTENT")
@org.hibernate.annotations.MapKey(columns = {@Column(name = "LANG_ID")}, targetElement = Language.class)
@Lob
private Map<Language,String> contents = new HashMap<Language, String>();
//...
Where
Language is an entity.
When I try to output the schema Hibernate generates, I get this
Code:
create table ISSUES (ISSUE_ID int8 not null, LOCKED bool, NUMBER int8 not null, PUBLICATION_DATE timestamp, NEWSLETTER_ID int8, primary key (ISSUE_ID))
create table ISSUE_CONTENTS (ISSUE_ID_FK int8 not null, CONTENT text, mapkey_LANG_ID int8 not null, primary key (ISSUE_ID_FK, mapkey_LANG_ID))
create table LANGUAGES (LANG_ID int8 not null, CODE varchar(255) unique, NAME varchar(255) unique, primary key (LANG_ID))
[...]
alter table ISSUE_CONTENTS add constraint FK95478BE0D350322E foreign key (mapkey_LANG_ID) references LANGUAGES
alter table ISSUE_CONTENTS add constraint FK95478BE095456796 foreign key (ISSUE_ID_FK) references ISSUES
[...]
So, instead of having the foreign key being called
LANG_ID, it is called
mapkey_LANG_ID.
It is misleading though, even if I would have put
@Column(name = "FOO"), it would have outputted the same generated SQL, with
mapkey_LANG_ID as the foreign key name.
My question is : I'm quite sure I missed something in my mapping. What did I do wrong ?