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

Bug 385275

Summary: Validation of named queries selecting derived properties from MappedSuperclass fails
Product: [WebTools] Dali JPA Tools Reporter: Andreas Gutlederer <a.gutlederer>
Component: FrameworkAssignee: dali.framework-inbox <dali.framework-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: a.gutlederer, amj87.iitr, karenfbutzke, neil.hauge, pascal.filion
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Andreas Gutlederer CLA 2012-07-17 05:15:18 EDT
Build Identifier: Version: Indigo Service Release 2 Build id: 20120216-1857

I have an entity TestA which implements the MappedSuperclass TestBase. TestBase has a property "key" of type string. TestA defines a NamedQuery "SELECT t.key FROM TestA t WHERE t.id = :id".

Eclipse now shows the query as invalid saying it doesn't know the property "key".

Reproducible: Always

Steps to Reproduce:
Example code:


@MappedSuperclass
public abstract class TestBase
{
	protected static final long serialVersionUID = 1L;
	protected String key;
	
	@Column(name="key", unique=true, nullable=false)
	public String getKey() { return key; }
	public void setKey(String key) { this.key = key; }
}


@Entity
@Table(name="TestA")
@SequenceGenerator(name="TestA_Seq")
@NamedQueries({
	@NamedQuery(name="TestQuerry",
		query="SELECT t.key FROM TestA t WHERE t.id = :id")
})
public class TestA extends TestBase
{
	private static final long serialVersionUID = 1L;
	private long id;
	private String keyA;
	private long version;
	
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="TestA_Seq")
	@Column(name="id")
	public long getId() { return id; }
	protected void setId(long id) { this.id = id; }
	
	@Column(name="keyA", unique=false, nullable=false)
	public String getKeyA() { return keyA; }
	public void setKeyA(String keyA) { this.keyA = keyA; }
	
	@Version
	@Column(name="oplock", unique=false, nullable=false)
	public long getVersion() { return version; }
	protected void setVersion(long version) { this.version = version; }
}
Comment 1 Ayushman Jain CLA 2012-07-17 05:37:56 EDT
JDT does not validate SQL queries. Are you using some plugin which does? 

If this is a compiler error and I'm missing something, can you please tell us what the error was exactly?
Comment 2 Andreas Gutlederer CLA 2012-07-17 05:57:03 EDT
It's not a compiler error, only a validation error. Sorry if I've put this into the wrong category, not sure where it belongs to.

Validation error message is: "The state field path 't.key' cannot be resolved to a valid type."

As a workaround, I've currently switched Window / Preferences / Java Persistence / JPA / Errors/Warnings / Queries and generators / Invalid or incomplete JPQL queries from Error to Warning.
Comment 3 Ayushman Jain CLA 2012-07-17 06:04:22 EDT
(In reply to comment #2)
> As a workaround, I've currently switched Window / Preferences / Java
> Persistence / JPA / Errors/Warnings / Queries and generators / Invalid or
> incomplete JPQL queries from Error to Warning.

So its JPA tools and not JDT ;)
Moving to Dali JPA tools.
Comment 4 Pascal Filion CLA 2012-07-18 10:29:18 EDT
I am unable to reproduce the issue in Indigo SR2 20120216-1857, if you still can reproduce it, please provide the exact steps. Thanks.
Comment 5 Andreas Gutlederer CLA 2012-07-18 10:42:06 EDT
Please try clicking Project / Clean / Clean all projects. This seems to trigger the validation and then shows me the query as invalid.

Without this step, eclipse at first shows the query as valid. If I continue to work on my project, it takes some time till some event I don't know occurs which seems to trigger the validation, resulting in the query displayed as invalid.
Comment 6 Karen Butzke CLA 2012-07-18 10:49:38 EDT
Do you have any orm.xml mapping files in this project?
Comment 7 Neil Hauge CLA 2012-07-18 10:53:13 EDT
I was also unable to reproduce with Indigo SR2 (WTP 3.3.2), with multiple project cleans and source changes.  Can you verify the version of Dali that you are using by viewing Help->About Eclipse->Installation Details->Features->Feature Name->Dali Java Persistence Tools - JPA Support.  Grab that entire version string and paste into the bug.

Perhaps there is a race condition that is at the root of this issue.  Let's verify the version information and proceed from there.
Comment 8 Andreas Gutlederer CLA 2012-07-18 11:02:30 EDT
(In reply to comment #6)
> Do you have any orm.xml mapping files in this project?
No.

Help->About Eclipse->Installation
Details->Features->Feature Name->Dali Java Persistence Tools - JPA Support:
Version: 3.0.2.v201110193010-7S7B7HFC7sRdlV6fmbQaRBF5

If you're not able to reproduce it, I can try to build a testcase project.