Search code examples
javahibernateannotation-processingjava-17

APT-generators stop working after update to Jakarta/Java17


I am working on a rather large project consisting of Spring and JavaEE-components. Right now, I am updating from javax to jakartaEE and also from Java 11 to 17. The build-tool is gradle with several modules, which depend on one another. I have already changed things to make the first modules compile and am now at the module containing the JPA entities.

Suddenly I find myself in a situation, where the metamodel is no longer created.

My basic assumption here is, that gradle itself is not participating in the generation of the Metamodel. Instead, the APT generators are handed over to javac which then recognizes them and executes them prior to compilation. I have debugged the gradle execution and the processorpath option of javac contains the jpa-metamodel.jar as expected. Therefore, I assume, I am rather looking at a Java than a Gradle problem.

I did a very simple POC project with the same Java/Hibernate versions and there it worked. With this project, I was able to verify, that the metamodel-generator issues a log statement. This statement is also issued, if the source code does not compile. So, it seems to be an indicator whether the modelgen is working at all. This log message is not written in my main project.

Also, next to the jpa-metamodel there are two other apt generators at work. Both show similar behavior, i.e. printing out a log line when working but not in my updated project. This brings me to the assumption, that it is no problem with the jpa-metamodel-gen but rather with APT itself.

Where should I be looking next?

EDIT

I have done some more researching. Via gradle --debug I was able to extract the actual javac call. Executing that from console shows the same error.

I reduced the number of elements to be compiled. It seems that putting an actual entity on the list of things to be compiled the APT generator goes dormant. Putting only a MappedEntity supertype on the list will still leave the APT active. WTF?

EDIT2

I am currently on my way to a reproducable exmaple. I've cut through a lot of business-related libs and right now, what I have is a havac call, where -processorpath only mentions the jpamodelgen and -classpath only mentions hibernate core (both in Version 6.1.6).

In this constellation the modelgen does not work. As soon as I eliminate the hibernate-core, it works.

Next step: I'll strip down the entities.


Solution

  • All right, that was unexpected. I condensed it down to a minimal example. Required for this issue to hit is a call similar to this one:

    javac \
      -processorpath hibernate-jpamodelgen-6.1.6.Final.jar\
      -classpath hibernate-core-6.1.6.Final.jar\
      BaseEntity.java 
    

    The additional condition, that triggers this issue is, that BaseEntity has to have a dysfunctional @Type annotation. @Type has changed its signature from Hibernate 5 to Hibernate 6 and my entities were not yet up to date.

    Interestingly enough, neither a generell compile error nor a specific one with other annotations (I tried a broken spring-Repository one) will stop the modelgen from working (as won't the fact, that the processorpath is incomplete in the example).

    I will report this as an issue to the hibernate project, as I believe, the modelgen should react more graceful in such a situation.

    Reported as bug here: https://hibernate.atlassian.net/browse/HHH-15946