Hello everybody,
I found the annotation MapKeyEnumerated limited.
Why? Becausa isn't possible to define the column name of the enumerated key.
Instead of using the defined MapKeyEnumerated annotation, I have to do, for defining enumerated key column name, with the followed annotation:
Code:
@ManyToMany
@MapKeyColumn(name = "SystemId")
@JoinTable(name = "DocumentType_DocumentClass", joinColumns = {
@JoinColumn(name = "DT_K_DOCUMENTO_AZIENDALE", referencedColumnName = "K_DOCUMENTO_AZIENDALE"),
@JoinColumn(name = "DT_K_SOTTO_APPLICAZIONE", referencedColumnName = "K_SOTTO_APPLICAZIONE") }, inverseJoinColumns = @JoinColumn(name = "DC_K_CLASSE_DOCUMENTALE"))
private Map<SystemId, DocumentClass> docClassMap = new HashMap<SystemId, DocumentClass>();
I think that @MapKeyEnumerated annotation should have an attribute to define in which column the key should be saved, but now, the annotation accept only the attribute value, which define the type used in mapping a map key enum type. I think an attribute like name of @MapKeyColumn is enough to achieve the result.
The problem born when I'm not free to define the column name in the db table.
Another limit is that attribute value cannot be a String. And you will asking why? Because, using maven, setting value as EnumType.String, hibernate cannot be used as provided jar, included in my project only when is necessary.
Also the example on javadoc are wrong...
Code:
public enum ProjectStatus {COMPLETE, DELAYED, CANCELLED, IN_PROGRESS}
public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}
@Entity public class Employee {
@ManyToMany
public Projects<ProjectStatus, Project> getProjects() {...}
@OneToMany
@MapKeyEnumerated([color=#FF0000]STRING[/color]) //must be EnumType.String
public Map<SalaryRate, Employee> getEmployees() {...}
...
}
Any Ideas of how improve?