I was reading through this tutorial: Advanced Spring Data JPA - Specifications and Querydsl , trying to learn about specifications to build a dynamic filtering system, and how I can implement it in my Maven java springboot project using Spring data JPA, of course, reading and watching other tutorials, I realized that most use the untype-safe way to get the Entity fields(calling entitie attributes as a String name), this was a major concern for me until I discovered the Meta Model thingy, and it provided my with the promise of type-safety and early error detection.
Now, the issue is that, I cant figure out how to get Meta Model to work, at first I was under the impression that it should be generated automatically by spring data jpa, then I discovered after further research into the matter that nope, it requires a dependecy, this depenedency to be precise: hibernate-jpamodelgen which I added into my pom.xml from here maven repository, but still it did not work, seems like adding the dependency alone does not work.
After further research, I found a lot of tutorials, but none of them seem to work, a lot of tutorials on Meta Model seem to just throw this most of the time but never show me how to add the folder to the classpath
"If you use maven, the generated metamodel classes are stored in the target/generated-classes folder. So you need to add this folder to the classpath definition in your IDE."
I also found this tutorial Hibernate Tips: How to automatically add Metamodel classes to your project By Thorben Janssen but he uses a completly different way.
Another tutorial suggested to add a plugin:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
But none seem to be working for me, what should I do.
This is the my full pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>monty.service</groupId>
<artifactId>content</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>content</name>
<description>This is a microservice for content service</description>
<properties>
<java.version>17</java.version>
<springdoc-openapi-starter-webmvc-ui.version>2.1.0</springdoc-openapi-starter-webmvc-ui.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<apache-tika.version>2.8.0</apache-tika.version>
<hibernate-jpamodelgen.version>6.2.6.Final</hibernate-jpamodelgen.version>
</properties>
<dependencies>
<!-- CORE -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- The hibernate validator for extra validation -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- The DTO Mapper library -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- The swagger library -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-starter-webmvc-ui.version}</version>
</dependency>
<!-- The file analysis service -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>${apache-tika.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers-standard-package</artifactId>
<version>${apache-tika.version}</version>
</dependency>
<!-- This library allows to generate the metamodels for entities -->
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate-jpamodelgen.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>