Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347380

Summary: Dotted notations unsupported in mappedBy annotation attribute
Product: [WebTools] Dali JPA Tools Reporter: elhanan Maayan <elh.mailgate>
Component: GeneralAssignee: Neil Hauge <neil.hauge>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: neil.hauge
Version: 2.3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
model (minus directory hirarachy) none

Description elhanan Maayan CLA 2011-05-26 17:19:20 EDT
given the following class (taken from the hr in xe oracle) 

Class Employee{
 
@OneToMany(mappedBy="id.employee") //dali says no, hibernate says yes
 Set<JobHistories> histories
}
@embeddable
class JobHistoryPK{
	
	@ManyToOne
	@JoinColumn(name="EMPLOYEE_ID")
	private Employee  employee
}
Class JobHisotry{

	private JobHistoryPK id;
}

dali would report 'In attribute 'jobHistories', the "mapped by" value 'id.employee' cannot be resolved to an attribute on the target entity.' 
however when actually running hibernate, the loading goes fine, (attempting to mess up the mappedBy, to a non-existent name, also fails hibernate).
Comment 1 Neil Hauge CLA 2011-05-31 12:13:46 EDT
Support for dot notation in mappedBy was added in bug 258528.

By looking at your example, there are a few things that I notice.  I assume that "Set<JobHistories> histories" is referring to "JobHistory".  Also, JobHistory is not marked as an Entity, and the "id" attribute is not marked as Embedded.  I'm thinking this is likely related to the validation that Dali is reporting, assuming the example matches the code.
Comment 2 elhanan Maayan CLA 2011-06-01 00:38:40 EDT
Created attachment 197056 [details]
model (minus directory hirarachy)
Comment 3 elhanan Maayan CLA 2011-06-01 00:41:59 EDT
(In reply to comment #1)
> Support for dot notation in mappedBy was added in bug 258528.
> 
> By looking at your example, there are a few things that I notice.  I assume
> that "Set<JobHistories> histories" is referring to "JobHistory".  Also,
> JobHistory is not marked as an Entity, and the "id" attribute is not marked as
> Embedded.  I'm thinking this is likely related to the validation that Dali is
> reporting, assuming the example matches the code.

i've i added a the complete model (minus the directory structure)

yes the jobHistory is annotated as an entity (even though it's a join table between jobs and employees) also note that all others entities have the following inheritence of persistable AbstractPersistable and PersistableEntity/Reference.

these classes are located in a different project, but it also happens when they are in the same project
Comment 4 Neil Hauge CLA 2011-06-01 11:12:40 EDT
Thanks for the model.  It appears that the specific cause of this validation error is based on the fact that relationships are not supported on EmbeddedId.  See Sect 11.1.15 in the JPA 2.0 spec - "Relationship mappings defined within an embedded id class are not supported."  As a result, we are not recognizing any relationships defined in JobHistorys's EmbeddedId.  You can test this by changing the EmbeddedId to Embedded

That said, the spec doesn't say that a JPA provider couldn't add this support, it just wouldn't be a standard.  As a user, doing this just prevents the application from being portable.  If you are using the Generic platform, Dali tries to keep your application portable by providing these warnings/errors.  In this case, a warning may be more appropriate.  You can tune the severity level by going to the JPA project properties or workspace preferences, look for JPA/Java Persistence -> Errors/Warnings page.

Dali is an extensible tooling platform, which means that Hibernate can fix this particular issue by updating their platform (which you can get from Hibernate tools) to support this case.  They can override the Generic model to return these attributes in the list of supported attributes, among other things.  This is probably the ultimate solution.

Marking this as Not Eclipse, but feel free to reopen if you think warranted, and let me know if you have any questions.