Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide JPA metamodel for better queries #392

Merged
merged 9 commits into from
Jun 4, 2024
Merged

Conversation

Ndacyayisenga-droid
Copy link
Member

Fixes #385

Copy link
Member

@hendrikebbers hendrikebbers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several points:

  • please do not use alpha dependency?
  • How are the static classes created? I can not see any build script / call or something. If a specific maven call is needed we should add that to the readme.
  • I can find 2 static classes but we have more entities
  • Is the code working? All the static attributes are never assigned to a concrete field. Maybe Spring does that as magic, no idea but have you checked that everything works as exected?

server/pom.xml Outdated
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>7.0.0.Alpha2</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the latest final version instead of an alpha

@Ndacyayisenga-droid
Copy link
Member Author

Is the code working? All the static attributes are never assigned to a concrete field. Maybe Spring does that as magic, no idea but have you checked that everything works as exected?

@hendrikebbers yea the code worked fine but I had manually created JPA Metamodel Classes which I think its kinda wrong. I included a build script in my pom.xml and am able to generate JPA Metamodel Classes for all the entities in the /server/target/generated-sources/annotations/com/openelements/benchscape/server/store/entities not sure yet thats the directory(/target) the JPA Metamodel Classes should be created. Still have a few build failures but trying to make everything useful :)

I added something like

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>17</source>
          <target>17</target>
          <annotationProcessorPaths>
            <path>
              <groupId>org.hibernate.orm</groupId>
              <artifactId>hibernate-jpamodelgen</artifactId>
              <version>6.2.0.Final</version> 
            </path>
          </annotationProcessorPaths>
        </configuration>
</plugin>

Am able to generate something like

package com.openelements.benchscape.server.store.entities;

import jakarta.persistence.metamodel.MapAttribute;
import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.StaticMetamodel;
import java.time.Duration;
import javax.annotation.processing.Generated;

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(MeasurementMetadataEntity.class)
public abstract class MeasurementMetadataEntity_ extends com.openelements.server.base.tenantdata.AbstractEntityWithTenant_ {

	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhThreadCount;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhWarmupIterations;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhWarmupBatchSize;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhWarmupTime;
	public static volatile MapAttribute<MeasurementMetadataEntity, String, String> environmentProperties;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhForks;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> jmhVersion;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitOriginUrl;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Boolean> gitDirty;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> systemArch;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> osName;
	public static volatile MapAttribute<MeasurementMetadataEntity, String, String> systemProperties;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhTimeout;
	public static volatile SetAttribute<MeasurementMetadataEntity, String> gitTags;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> osVersion;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> jvmVersion;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> jvmName;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Duration> jmhMeasurementTime;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhMeasurementBatchSize;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Long> systemMemory;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitCommitId;
	public static volatile SingularAttribute<MeasurementMetadataEntity, String> gitBranch;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> jmhMeasurementIterations;
	public static volatile SingularAttribute<MeasurementMetadataEntity, Integer> systemProcessors;

	public static final String JMH_THREAD_COUNT = "jmhThreadCount";
	public static final String JMH_WARMUP_ITERATIONS = "jmhWarmupIterations";
	public static final String JMH_WARMUP_BATCH_SIZE = "jmhWarmupBatchSize";
	public static final String JMH_WARMUP_TIME = "jmhWarmupTime";
	public static final String ENVIRONMENT_PROPERTIES = "environmentProperties";
	public static final String JMH_FORKS = "jmhForks";
	public static final String JMH_VERSION = "jmhVersion";
	public static final String GIT_ORIGIN_URL = "gitOriginUrl";
	public static final String GIT_DIRTY = "gitDirty";
	public static final String SYSTEM_ARCH = "systemArch";
	public static final String OS_NAME = "osName";
	public static final String SYSTEM_PROPERTIES = "systemProperties";
	public static final String JMH_TIMEOUT = "jmhTimeout";
	public static final String GIT_TAGS = "gitTags";
	public static final String OS_VERSION = "osVersion";
	public static final String JVM_VERSION = "jvmVersion";
	public static final String JVM_NAME = "jvmName";
	public static final String JMH_MEASUREMENT_TIME = "jmhMeasurementTime";
	public static final String JMH_MEASUREMENT_BATCH_SIZE = "jmhMeasurementBatchSize";
	public static final String SYSTEM_MEMORY = "systemMemory";
	public static final String GIT_COMMIT_ID = "gitCommitId";
	public static final String GIT_BRANCH = "gitBranch";
	public static final String JMH_MEASUREMENT_ITERATIONS = "jmhMeasurementIterations";
	public static final String SYSTEM_PROCESSORS = "systemProcessors";

}

@hendrikebbers
Copy link
Member

@Ndacyayisenga-droid the code that you show in your comment is exactly what I would suspect.

The addition to the pom will automatically trigger the generation of the code whenever java is compiled. Since it is no "hand-written" code it is added to the generated-sources folder in the target directory (internally the Hibernate lib uses the Java Annotation processor standard to generate the new sources <- just a technical detail).
The generated sources will be part if the project when starting the server and therefore everything should work as expected.

The interesting point here is that the generated sources will not be commited by git (since the target folder is ignored). But since it happens automatically when java compilation is happened (like when calling mvn verify) everyone will have that generated sources automatically.

So what you put in your comment (the pom addition) should be what is part of the PR. I assume nothing more is needed :)

@Ndacyayisenga-droid Ndacyayisenga-droid merged commit 1e5d1ff into main Jun 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide JPA metamodel for better queries
2 participants