This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 217556 - JPA canonical metamodel is neither generated nor used for entity classes specified only in orm.xml
Summary: JPA canonical metamodel is neither generated nor used for entity classes spec...
Status: REOPENED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.2
Hardware: All All
: P2 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-28 23:06 UTC by flutter
Modified: 2013-06-18 20:24 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
IDE log (179.29 KB, text/plain)
2012-08-28 23:07 UTC, flutter
Details
sample project (6.45 MB, application/zip)
2012-09-11 16:12 UTC, Sergey Petrov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description flutter 2012-08-28 23:06:57 UTC
Product Version = NetBeans IDE 7.2 (Build 201207301726)
Operating System = Mac OS X version 10.8.1 running on x86_64
Java; VM; Vendor = 1.7.0_06
Runtime = Java HotSpot(TM) 64-Bit Server VM 23.2-b09

JPA = EclipseLink Version 2.0.3

Netbeans seems to have massive problems in JPA tooling if entity classes are specified in orm.xml only, rather than being annotated with source-level annotations.
I am generating entity classes via JAXB from a XSD schema. This setup requires the JPA mapping data being specified as XML (orm.xml), because annotations in generate JAXB classes will be overwritten by XJC.
However, the NetBeans IDE seems to have two major and one minor issue with this configuration:
1. If there is no class with a source-level annotation from the javax.persistence package, the EclipseLink annotation processor generating the canonical metamodel will never be invoked, so there will be no canonical metamodel classes generated.
2. If I manage to get the ap invoked by annotating a dummy class, all generated metamodel classes NOT generated from a source-annotated class are be invisible to the IDE source editor and consequently are marked in red and seen as "undefined symbols". When invoking the build, the projects builds fine, however, since the metamodel classes are actually existing.
3. (minor) In the "persistence.xml" GUI editor, classes annotated in orm.xml only are not shown as selectable entity classes. You can, however, add them manually in the persistence.xml XML source.
Comment 1 flutter 2012-08-28 23:07:02 UTC
Created attachment 123680 [details]
IDE log
Comment 2 Petr Jiricka 2012-09-04 11:19:51 UTC
Does not sound like a P1 defect.
Comment 3 Sergey Petrov 2012-09-04 12:22:13 UTC
Persistence support in nb do not recognize orm.xml at all, it's just absent feature. Regarding metamodel it may be also an issue (feature?) of eclipselink provider as if processor is present on classpath and registered as a service nb have nothing with metamodel generation either it works or doesn't work.
Comment 4 Sergey Petrov 2012-09-04 12:38:36 UTC
on another side, metamodel is generated by annotation processor, it means processing of annotations and say nothing about orm.xml and processing anything except annotations, it may be expected not to work even on eclipselink. if there is no annotations annotation processor may not be invoked by java compiler.

from specification "After scanning the source files and classes on the command line to determine what annotations are present, the compiler queries the processors to determine what annotations they process. When a match is found, the processor will be invoked. "

http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html#processing

please reopen if I miss something
Comment 5 flutter 2012-09-05 16:59:24 UTC
When configuring the project with maven or custom ant build system, the metamodel is actually generated correctly, because the standard annotation processor will be invoked during "compile" phase.
NetBeans, however, seems to have two issues with this:

1. When using the default ant build model, orm.xml isn't copied to the "build" directory just before compile, because it is excluded by the default ant build pattern. So, the eclipseLink annotation processor won't see orm.xml, it is simply not included in the temp files and resources for the build.

2. Even after the metamodel ist generated, and even if the JPA module is packaged in a jar, metamodel classes are not seen by NetBeans source editor in a dependent project referencing this JAR. This is really weird. I already tried clearing NetBeans cache, but somehow NetBEans just seems to ignore classes ending in "_" on the class path.
Comment 6 flutter 2012-09-05 17:00:33 UTC
When configuring the project with maven or custom ant build system, the metamodel is actually generated correctly, because the standard annotation processor will be invoked during "compile" phase.
NetBeans, however, seems to have two issues with this:

1. When using the default ant build model, orm.xml isn't copied to the "build" directory just before compile, because it is excluded by the default ant build pattern. So, the eclipseLink annotation processor won't see orm.xml, it is simply not included in the temp files and resources for the build.

2. Even after the metamodel ist generated, and even if the JPA module is packaged in a jar, metamodel classes are not seen by NetBeans source editor in a dependent project referencing this JAR. This is really weird. I already tried clearing NetBeans cache, but somehow NetBEans just seems to ignore classes ending in "_" on the class path.
Comment 7 Sergey Petrov 2012-09-05 19:03:15 UTC
1st one is related to absent orm.xml support, may be some ap is invoked always even without annotations and with current lack of orm.xml support isn't enhancement request. entire nb persistence model is based on annotations only and it's quite a big task, yet it may not be so hard to copy orm.xml as a minor part of orm.xml support.

2nd one may need more evaluation but if ant project is custom it may not handle all source roots/generated classes properly. I'll try to check maven tomorrow. there is no "ignore" for '_' classes as I know and these generated classes are visible to nb in case of annotations usage as I know, also all generated classes should be shown under 'generated-classes' node of a project and if it's not it's either project configuration problem or some core problem. Will reevaluate the issue tomorrow.
Comment 8 Sergey Petrov 2012-09-05 20:13:47 UTC
if I use annotations in maven I see generated classes node and everything is recognized. if hack to use some dummy entity is used dummy_ is recognized but other classes which do not have annotations are nor recognized.

Tomas, do you have any ideas why generated in 'generated sources' classes may not be parsed?
Comment 9 Sergey Petrov 2012-09-05 20:28:30 UTC
project at the same time is build succesfully if use metamodel generated for classes from orm.xml. only editor do not recognize these files, tried also withou compile/save and still have the issue.

//regarding initial issue I'm not able to generate metamodel without dummy class in maven and it's ok in my opinion(and the same with customized with orm.xml copy ant project)
Comment 10 flutter 2012-09-05 21:07:09 UTC
That's exactly the behavior I experienced. It seems strange that NetBeans editor sees metamodel classes generated from annotated entity classes, but not other classes in the generated-sources folder.

I also agree that it's OK (at least from a NetBeans perspective) that you need at least one JPA-annotated class to generate the metamodel.
It would be difficult to trick the annotation processor into reading orm.xml without being triggered by *some* JPA-related annotation, as by design (you pointed out earlier) annotation processor will be selected by the compiler only if a suitable annotation is encountered during parse of the source code. In any case, the latter case is not a NetBeans issue, but rather an enhancement request for eclipseLink et. al. They should provide a separate ant/maven/whatever plugin to generate the metamodel independently of javac/apt.
Comment 11 Sergey Petrov 2012-09-06 10:57:38 UTC
tries a small hack to copy orm.xml in CopyResourcesIndexer to cache dir, and after cache update (have to change all files) I got completion for both - annotated and not annotated entities.

it may not be so hard to hardcode orm.xml copy but in real persistence.xml should be analized and mapping files need to be copied as it may be named differently. on another side hardcoded case may work for significant percent of cases. we need to discuss if try to support orm.xml at some minimum level as unrecognized classes are part of this support.
Comment 12 Sergey Petrov 2012-09-07 12:56:00 UTC
there is a chance to have minimum orm.xml support in 7.3 or next. orm.xml will be copied with default build script in ant and parsing will use it also. only orm.xml name for mapping file will be supported by nb at this stage. no support with 'add entity' and most other jpa nb feature is expected to be done in next release.
Comment 13 Sergey Petrov 2012-09-11 14:10:24 UTC
http://hg.netbeans.org/web-main/rev/b0800dbb2a05

got some problems similar to http://stackoverflow.com/questions/9227021/jpa-xml-mapping-not-finding-fields i.e. field can't be loaded.

metamodel is generated in  'generated sources' but can't get it to be parsed properly, looks like it's dependent on classpath build strategy or some other. may cause postpone to support orm.xml even at minimum level
Comment 14 Sergey Petrov 2012-09-11 15:12:18 UTC
if I remove cache and restart ide I have proper cc/recognition for metampodel generated from orm.xml, it may be some cache refresh issue for usual classes.
Comment 15 Sergey Petrov 2012-09-11 16:12:39 UTC
Created attachment 124177 [details]
sample project
Comment 16 Sergey Petrov 2012-09-11 16:18:41 UTC
Steps I have an issue with:
-create j2se project
-create an entity with persistence unit creation
-copy orm.xml from attached project and also not annotated entity and update packages in orm.xml if necessary
Comment 17 Sergey Petrov 2012-09-11 16:20:40 UTC
forget next(but generation by ant works without these steps):
-it's good to add copied non-anntated entity into <class> node in persistence.xml
and add <mapping-file>orm.xml</mapping-file> into persistence.xml (see persistence.xml in attached project)
Comment 18 Quality Engineering 2012-09-12 02:11:25 UTC
Integrated into 'main-golden', will be available in build *201209120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/4eabe682d692
User: Sergey B. Petrov <sj-nb@netbeans.org>
Log: #217556 copy orm.xml in ant by default
Comment 19 Tomas Zezula 2012-09-14 08:41:55 UTC
The problem is caused by misusage of the annotation processor.
The AP is executed only on annotated elements. Having an unannotated element and one dummy annotated does not work in incremental compilation.
Comment 20 Sergey Petrov 2012-09-14 11:23:18 UTC
looks like remaining issue may be considered as invalid even it looks strange from user point of view as you can see classes i 'generated' folder but editor 'don't see it'. either it's just said we have extremly limited support for orm.xml, I can keep default copy of orm.xml for ant project but anything else can be converted into enhancement request then.
Comment 21 Sergey Petrov 2012-09-17 08:12:42 UTC
I'm not sure anything can be done, but will keep as enhancment for now. AP may generate some classes at random depending on configuratiuon and nb may not handle each case properly, as example see your case:
you have dummy class  and build a project, dummy metamodel will be generated, now add some class to your orm.xml, and build the project, not metamodel will be generated for orm.xml, only clean&build will produce desired output, compilation order matter in this case.
Comment 22 samshm 2013-06-18 20:24:18 UTC
Netbeans 7.3.1 still fails to generate metamodel.