i want to Map a map in JPA, but I get a Exception:
My java-code looks like that:
Issue.java:
@ElementCollection
@CollectionTable(
name="ISSUE_EMPLOYEE",
joinColumns=@JoinColumn(name="ISSUE_ID", referencedColumnName="ID")
)
@MapKeyColumn(name="EMPLOYEEPOSITION_ID")
@MapKeyConvert("myEnumConverter")
@JoinColumn(name="EMPLOYEE_ID")
private Map<EmployeePosition, Employee> namedEmployees = new Hashtable<EmployeePosition, Employee>();
EmployeePosition is a Enum andEmployee is a Entity.
I get this Exception :
Internal Exception: java.sql.SQLException: ORA-00904: “EMPLOYEES”: invalid identifier
Error Code: 904
Call: INSERT INTO ISSUE_EMPLOYEE (ISSUE_ID, EMPLOYEES, EMPLOYEEPOSITION_ID) VALUES (?, ?, ?)
bind => [27, [B@18b85d, SERVICE]
It seems to ignore the @JoinColumn annotation and tries to insert the object in the DB.
What´s wrong with my mapping/Is it possible to match Entities like this?
As far as I understand, you need
@OneToManyinstead of@ElementCollectionwhen value of aMapis an entity. Something like this:EDIT: The mapping above works fine in Hibernate, but doesn’t work in EclipseLink.
EMPLOYEEPOSITION_IDcolumn inISSUE_EMPLOYEEis created, but not used in queries. It happens not only with enum keys, but also with other primitive types.It looks like a bug in EclipseLink. I can’t find in in their Bugzilla, so perhaps it would be better to report it.