0

I use Redis OM Spring Entity Streams, which provides a Java 8 Streams interface to Query Redis JSON documents using RediSearch.

I want to generate a metamodel like Person$ to run the code below. But I couldn't figure out how to generate the metamodel for the Person document entity. Can you please help me to find out a way to generate the metamodel? Thanks in advance.

> // Find people by age range   public Iterable<Person>
> findByAgeBetween(int minAge, int maxAge) {
>     return entityStream //
>         .of(Person.class) //
>         .filter(Person$.AGE.between(minAge, maxAge)) //
>         .sorted(Person$.AGE, SortOrder.ASC) //
>         .collect(Collectors.toList());   }
efk
  • 41
  • 5

1 Answers1

0

For Gradle, you can add the OM dependency as an annotation processor using the annotationProcessor call in the dependencies block like:

ext {
  redisOmVersion = '0.8.0'
}

dependencies {
  implementation: "com.redis.om:redis-om-spring:$redisOmVersion"
  annotationProcessor "com.redis.om:redis-om-spring:$redisOmVersion"
}

For Maven, things normally just work, when you run ./mvnw spring-boot:run. Some users have experienced this not being the case, in which I recommend to explicitly declaring the maven-compiler-plugin in the case below it's pair with an app create with start.spring.io v3.0.4 (all other versions can be inherited from the parent poms):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven-compiler-plugin.version}</version>
  <configuration>
    <annotationProcessorPaths>
      <path>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <version>3.0.4</version>
      </path>
      <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
      </path>
      <path>
        <groupId>com.redis.om</groupId>
        <artifactId>redis-om-spring</artifactId>
        <version>0.8.0</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>

Also, in case you are using IntelliJ Idea, see https://www.jetbrains.com/help/idea/annotation-processors-support.html#annotation_processing

BSB
  • 1,516
  • 13
  • 14
  • thanks for your answer @BSB . I am new to Metamodel concept, please bear with me here:) I found the metamodel classes under the folder target/generated-sources/annotations . And I moved them to src folder. After that I ran mvn clean install. And install failed due to metamodel classes. How can I solve this problem? – efk Mar 23 '23 at 08:24
  • 1
    You shouldn't move them, just add that folder to your IDE's source path. – BSB Mar 23 '23 at 20:52
  • Does this work with Kotlin too? – Lucas León May 20 '23 at 06:30
  • 1
    Now it does, thanks for the assist @LucasLeón – BSB May 29 '23 at 18:07