Closed sysmat closed 4 weeks ago
I use jpa routinely at work with hibernate-jpamodelgen similar included as you do and it works. Please provide a minimal reproducer, so that it can be investigated.
I have a similar problem with other annotation processors generating sources and seen that this just seem to happen if I add a module-info to the project. Could it be that the internal compiler does not include the generated classes to the module?
I've created a simple reproducer with mapstruct and record-builder here: https://github.com/balta3/annotation-processor-netbeans-reproducer
Interestingly in this project it makes no difference if there is a module-info or not, it will simply not detect the generated classes in the editor, but it is compiling without problems using maven.
@balta3:
I've created a simple reproducer with mapstruct and record-builder here: https://github.com/balta3/annotation-processor-netbeans-reproducer
This is a different problem/issue. NetBeans followed the maven-compiler-plugin
documentation, which documents, that the child element of annotationProcessorPaths
is called path
. And if you do that, all is well (i.e. works):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<parameters>true</parameters>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-processor</artifactId>
<version>42</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
However, some clever soul though that would be to hard for users and declared (https://maven.apache.org/guides/mini/guide-configuring-plugins.html#mapping-collections-and-arrays):
Mapping to collections works in much the same way as mapping to arrays. Each item is given in the XML as dedicated element. The element name does not matter in that case.
It would have been to easy to require users to enter the "right" xml elements (WTF!)
Edit: tracked as #7658
@sysmat this is not a NetBeans problem, but a problem of your setup. hibernate jpamodel in version 4.3.11 was release 2015, long before JDK 9 was released. In JDK 8 JAXB (java xml bind) was part of the JDK and hibernate used it. JAXB was removed from the JDK somewhere between 9 and 11. Today it lives on as an independent module jakarta XML bind.
If I remember correctly I worked around this problem @work by adding the jaxb implementation as an explicit dependency:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.11.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-proc:only</arg>
</compilerArgs>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.9</version>
</dependency>
</dependencies>
</configuration>
</plugin>
I like NB, but it is sad to see how NB getting worse & worse
@sysmat I explicitly asked for a demonstrator, you did not react. I also indicated, that I had a similar problem @work and fixed it as described. That soltution has the benefit, that it is then possible to build JDK 8 code with a more modern JDK (using the release option of javac). Not sure what is the problem you try to address here.
- @matthiasblaesing it generate classes, in cm maven package works fine, the problem is DX in NetBeans as error not found
I don't understand what you are saying here. What is "cm" what is "DX"?
- target\generated-sources\annotations\si\arnes\db\aris\entity they are present
- why then works in Eclipse & IntelliJ
The sources are present when the maven build is invoked, but they are the output of the compilation, not the input. I think your assumption is wrong, that the code on disc is used by NetBeans. NetBeans hooks directly into the Javac, so it does not need the on disc files as it can process the files in flight. That in turn also means, that the javac needs to be able to execute the annotation processors and that does not work in this case.
I assume that Eclipse and IntelliJ hook differently into the annotation processing/javac and thus react different. Both approaches have benefits and problems.
- even restart NB dosen't help it is NB problem
No it just validates, that NetBeans is consistent. It would be more problematic, if the problem vanishes after a NetBeans restart.
I like NB, but it is sad to see how NB getting worse & worse
This does not help your case. If you did not notice it, I try to help you.
@lahodaj could you please have a look at this, whether my interpretation is correct and maybe you can better explain, why this problem exists for NB, but not for Eclipse. You might be able to turn my "gut feeling" into "I know the NB infrastructure".
* in first post I append image from NB and generated files are there in Ide
Yes they are. BUT they are not considered for compilation. For annotation processing the generated source is a compilation output, not an input. My understanding is, that you need to separate two different generated-source
types:
generated-sources
from general maven plugins, like the jakarta webservices integration. These generate sources and the sources are then consumed by the compiler together with the sources from src/main/java
generated-sources
from annotation processing. These are not consumed by the compiler
, but are generated by the compiler. They are present, so that you can look at them or bundle them in a src jar, not for the compilers benefit.The latter it might make sense, when you consider, that annotation processor can not only generate source code for the compilation, but can also directly influence the generated bytecode (bytecode weaving). One such example is lombok. lombok can generate getters, setters, equals, hashCode, toString and probably more methods on the fly, based on annotations. To do this it hooks into the compilation process and directly injects the code into the class file, it does not write source code. An approach that reads the generated sources would not be helpful here.
Hmm, dam so you are saying that is not possible to use it in NB
Hmm, dam so you are saying that is not possible to use it in NB
Which part of
If I remember correctly I worked around this problem https://github.com/work by adding the jaxb implementation as an explicit dependency
was unclear? What I wanted to say:
That fix will also allow you to compile with JDK 9+, if you use the release flag.
Apache NetBeans version
Apache NetBeans 22
What happened
I have hibernate-jpamodelgen for JPA CriteriaQuery, maven cmd it works fine, but NB has problems
Language / Project Type / NetBeans Component
java , maven , hibernate
How to reproduce
Did this work correctly in an earlier version?
No / Don't know
Operating System
win 11
JDK
jdk 8-21
Apache NetBeans packaging
Apache NetBeans provided installer
Anything else
Are you willing to submit a pull request?
Yes