| Summary: | Misleading exception with incorrect derived id mapping | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Sabine Heider <sabine.heider> |
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | minor | ||
| Priority: | P2 | CC: | eclipselink.foundation-inbox, guy.pelletier, michael.f.obrien, tom.ware |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows Vista | ||
| See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=330755 | ||
| Whiteboard: | |||
It seems that I was mistaken with my last remark about nested embeddables to be used as embedded ids because when I tried it out, I ended up with the same [EclipseLink-7298] exception. I think, however, that they should actually work - at least I couldn't find any restriction like that in the JPA 2 spec. It only says that the embeddable must contain neither relationships nor @Id annotations. Or is there another statement in the spec that I missed? If you agree with me that nested embeddables should also be usable as embedded ids, I would file a separate bug for that. Please let me know. My initial look at the spec indicates we should support Embeddables as you mention above. This issue appears to be valid. BTW: The relationship to a MappedSuperclass is incorrect. To truely verify this bug we would have to verify it occurs when that relationship is mapped correctly. Hi Tom, I know that the mapping above is invalid. (The example actually works quite well once you map the class Department as @Entity instead of @MappedSuperclass.) My point here is simply that the error message was so confusing to our application developer that he was unable to find out himself what was wrong. A message like "The target of the many-to-one relationship Project.department is not an entity" or something like that would have been much more helpful. I was just wondering whether it would be possible to improve the error message for that case. The other issue is actually a separate issue, and I have opened a separate bug for it: Bug 330755. The problem is somehow related though, because it came up when the same user explained to me what he actually wanted to achieve with the erroneous mapping. Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines With the fix to bug 330755, the exception now seen on this model (when Department is a tagged as a mapped superclass) is: Exception Description: [class org.eclipse.persistence.testing.models.jpa.ddlgeneration.Project] uses a non-entity [class org.eclipse.persistence.testing.models.jpa.ddlgeneration.Department] as target entity in the relationship attribute [field department]. That exception was being hidden with the exception from bug 330755. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
A user tried the following example (taken from the "Pro JPA 2" book, listings 10-14, 10-5 but modified incorrectly): @Entity public class Project { @EmbeddedId private ProjectId id; @MapsId("dept") @ManyToOne @JoinColumns({ @JoinColumn(name="DEPT_NUM", referencedColumnName="NUM"), @JoinColumn(name="DEPT_CTRY", referencedColumnName="CTRY")}) private Department department; //... } @Embeddable public class ProjectId implements Serializable { @Column(name="P_NAME") private String name; @Embedded private DeptId dept; //... } @MappedSuperclass // this is the error, must be @Entity public class Department { @EmbeddedId private DeptId id; @OneToMany(mappedBy="department") private List<Project> projects; //... } @Embeddable public class DeptId { @Column(name="NUM") private int number; @Column(name="CTRY") private String country; //... } The error message thrown was: [EclipseLink-7298]: The mapping [dept] from the embedded ID class [class imported.ProjectId] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [id] from the source [class imported.Project]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded. This exception is somehow misleading as it does not identify the root cause (the wrong relationship mapping to a non-entity). It is also not quite true: the embeddable may also contain other embeddables. Is there maybe any chance to have this improved and throw a more suitable exception?