Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 330395 - @Override annotation is causing a ValidationException when trying to generate metamodel of an entity using property access level
Summary: @Override annotation is causing a ValidationException when trying to generate...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 323672 336599 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-16 14:28 EST by Pascal Thivent CLA
Modified: 2022-06-09 10:30 EDT (History)
6 users (show)

See Also:


Attachments
testcase (4.38 KB, application/x-zip-compressed)
2010-11-16 14:35 EST, Pascal Thivent CLA
no flags Details
Proposed changes (2.63 KB, patch)
2010-11-19 09:17 EST, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Thivent CLA 2010-11-16 14:28:00 EST
Build Identifier: 2.1.1.v20100817-r8050

Given an entity using **property access level** and having methods annotated with `@Override`, the annotation processor fails to generate the metamodel class. Here is the output of a sample project demonstrating the issue:

[INFO] diagnostic error: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method toString] on entity class [class com.acme.Foo] does not have a corresponding setter method defined.


An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method toString] on entity class [class com.acme.Foo] does not have a corresponding setter method defined.
	at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:373)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:554)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:699)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)
	at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.executeWithExceptionsHandled(AbstractAnnotationProcessorMojo.java:261)
	at org.bsc.maven.plugin.processor.AbstractAnnotationProcessorMojo.execute(AbstractAnnotationProcessorMojo.java:129)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: Exception [EclipseLink-7174] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The getter method [method toString] on entity class [class com.acme.Foo] does not have a corresponding setter method defined.
	at org.eclipse.persistence.exceptions.ValidationException.noCorrespondingSetterMethodDefined(ValidationException.java:1917)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod.isValidPersistenceMethod(MetadataMethod.java:243)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod.isValidPersistenceMethod(MetadataMethod.java:222)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorMethods(ClassAccessor.java:387)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:329)
	at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcessForCanonicalModel(EntityAccessor.java:649)
	at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnit.preProcessForCanonicalModel(PersistenceUnit.java:457)
	at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:364)
	... 30 more
[ERROR] error on execute: error during compilation
[INFO] ------------------------------------------------------------------------


Reproducible: Always

Steps to Reproduce:
1. Run `mvn generate-sources` on the attached project.
Comment 1 Pascal Thivent CLA 2010-11-16 14:35:45 EST
Created attachment 183262 [details]
testcase
Comment 2 Pascal Thivent CLA 2010-11-17 04:45:37 EST
There are some workarounds:

- use FIELD access level
- comment the @Override 

But these workaround are not really acceptable, at least for me. 

- I have some cases where I do not want to use field access level 
- having to comment @Override on my code base is... a pain.

Not even mentioning the time I lost on this issue :) Thanks in advance.
Comment 3 Karen Butzke CLA 2010-11-18 11:59:02 EST
Try adding @Transient to the toString() method as another not great workaround. EclipseLink *should* be looking for methods annotated with JPA annotations, not just any annotation. I am upping the severity as well, this breaks metamodel generation with property access pretty badly
Comment 4 Pascal Thivent CLA 2010-11-18 12:26:10 EST
(In reply to comment #3)
> Try adding @Transient to the toString() method as another not great workaround.
> EclipseLink *should* be looking for methods annotated with JPA annotations, not
> just any annotation. I am upping the severity as well, this breaks metamodel
> generation with property access pretty badly

Thank you for the feedback. Actually, I tried using @Transient on the toString() method but it doesn't help, the annotation processor then complains with the following error.


[INFO] diagnostic error: Exception [EclipseLink-7153] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Mapping annotations cannot be applied to fields or properties that have a @Transient specified. [method toString] is in violation of this restriction.
...

At least, the annotation processor is consistent... 

Clearly, it is treating any annotation like @Override, @Deprecated, etc as a JPA annotation. And shouldn't.
Comment 5 Guy Pelletier CLA 2010-11-19 09:17:06 EST
Created attachment 183469 [details]
Proposed changes
Comment 6 Guy Pelletier CLA 2010-11-19 09:34:38 EST
Changes have been submitted to the 2.2 stream.

Reviewed: Tom Ware

Once the 2.1.3 stream opens up, I'll submit the changes there as well.
Comment 7 Guy Pelletier CLA 2010-11-25 11:01:25 EST
*** Bug 323672 has been marked as a duplicate of this bug. ***
Comment 8 Guy Pelletier CLA 2011-02-10 09:54:18 EST
*** Bug 336599 has been marked as a duplicate of this bug. ***
Comment 9 Guy Pelletier CLA 2011-04-19 14:38:06 EDT
Changes were submitted to the 2.1.4 stream.
Comment 10 David Minsky CLA 2011-12-08 14:02:15 EST
Trunk checkin (2.2) r8525
2.1 branch checkin r9242
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:30:07 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink