Skip to content

Commit

Permalink
Merge pull request quarkusio#39715 from marko-bekhta/fix/i39299-orm-a…
Browse files Browse the repository at this point in the history
…nnotations-on-package-info

Update Hibernate ORM package/class processing rules
  • Loading branch information
gsmet authored Mar 28, 2024
2 parents 8846d14 + 9d58018 commit a58edc4
Show file tree
Hide file tree
Showing 24 changed files with 94 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,8 @@ public static Map<String, Set<String>> getModelClassesAndPackagesPerPersistenceU
}

for (String modelPackageName : jpaModel.getAllModelPackageNames()) {
Set<String> persistenceUnitNames = packageRules.get(modelPackageName);
// Package rules keys are "normalized" package names, so we want to normalize the package on lookup:
Set<String> persistenceUnitNames = packageRules.get(normalizePackage(modelPackageName));
if (persistenceUnitNames == null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.hibernate.orm.packages;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.transaction.UserTransaction;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.TransactionTestUtils;
import io.quarkus.test.QuarkusUnitTest;

public class PackageLevelAnnotationWithExplicitPackagePropertyTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(TransactionTestUtils.class)
.addPackage(PackageLevelAnnotationWithExplicitPackagePropertyTest.class.getPackage()))
.withConfigurationResource("application.properties")
.overrideConfigKey("quarkus.hibernate-orm.packages", "io.quarkus.hibernate.orm.packages");

@Inject
EntityManager entityManager;

@Inject
UserTransaction transaction;

@Test
public void test() {
ParentEntity parent1 = new ParentEntity("parent1");

inTransaction(() -> {
entityManager.persist(parent1);
});

inTransaction(() -> {
final List<ParentEntity> list = entityManager.createNamedQuery("test", ParentEntity.class)
.getResultList();
assertThat(list.size()).isEqualTo(1);
});
}

private void inTransaction(Runnable runnable) {
TransactionTestUtils.inTransaction(transaction, runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

import org.hibernate.annotations.Filter;

@Entity
@Filter(name = "filter")
public class ParentEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@NamedQuery(name = "test", query = "from ParentEntity")
@FilterDef(name = "filter", defaultCondition = "true")
package io.quarkus.hibernate.orm.packages;

import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.NamedQuery;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import jakarta.ws.rs.core.MediaType;

import io.quarkus.hibernate.orm.PersistenceUnit;
import io.quarkus.it.jpa.postgresql.defaultpu.EntityWithXml;
import io.quarkus.it.jpa.postgresql.defaultpu.Person;
import io.quarkus.it.jpa.postgresql.defaultpu.SequencedAddress;
import io.quarkus.it.jpa.postgresql.otherpu.EntityWithXmlOtherPU;
import io.quarkus.narayana.jta.QuarkusTransaction;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import java.time.LocalDate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

public enum Status {
LIVING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${postgres.url}
quarkus.datasource.jdbc.max-size=8

quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql
quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql.defaultpu
quarkus.hibernate-orm.database.generation=drop-and-create

#Necessary for assertions in JPAFunctionalityInGraalITCase:
Expand All @@ -14,4 +14,5 @@ quarkus.native.additional-build-args=-J-Dio.quarkus.jdbc.postgresql.graalvm.diag

# Define non-default PU so that we can configure a custom XML format mapper. The default PU is using the default mapper.
quarkus.hibernate-orm."other".datasource=<default>
quarkus.hibernate-orm."other".packages=io.quarkus.it.jpa.postgresql.otherpu
quarkus.hibernate-orm."other".packages=io.quarkus.it.jpa.postgresql.otherpu
quarkus.hibernate-orm."other".database.generation=drop-and-create
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import jakarta.ws.rs.core.MediaType;

import io.quarkus.hibernate.orm.PersistenceUnit;
import io.quarkus.it.jpa.postgresql.defaultpu.EntityWithJson;
import io.quarkus.it.jpa.postgresql.defaultpu.MyUUIDEntity;
import io.quarkus.it.jpa.postgresql.defaultpu.Person;
import io.quarkus.it.jpa.postgresql.defaultpu.SequencedAddress;
import io.quarkus.it.jpa.postgresql.otherpu.EntityWithJsonOtherPU;
import io.quarkus.narayana.jta.QuarkusTransaction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import io.quarkus.it.jpa.postgresql.defaultpu.Address;
import io.quarkus.it.jpa.postgresql.defaultpu.Customer;
import io.quarkus.it.jpa.postgresql.defaultpu.NotAnEntityNotReferenced;
import io.quarkus.it.jpa.postgresql.defaultpu.WorkAddress;

/**
* Various tests for the JPA integration.
* WARNING: these tests will ONLY pass in native mode, as it also verifies reflection non-functionality.
Expand All @@ -32,8 +37,9 @@ public String test() throws SQLException, TransformerException, IOException {
makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(errors);
makeSureAnnotatedEmbeddableAreAccessibleViaReflection(errors);
String packageName = this.getClass().getPackage().getName();
makeSureClassAreAccessibleViaReflection(packageName + ".Human", "Unable to enlist @MappedSuperclass", errors);
makeSureClassAreAccessibleViaReflection(packageName + ".Animal", "Unable to enlist entity superclass", errors);
makeSureClassAreAccessibleViaReflection(packageName + ".defaultpu.Human", "Unable to enlist @MappedSuperclass", errors);
makeSureClassAreAccessibleViaReflection(packageName + ".defaultpu.Animal", "Unable to enlist entity superclass",
errors);
if (errors.isEmpty()) {
return "OK";
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.Embeddable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

/**
* @author Emmanuel Bernard emmanuel@hibernate.org
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import java.time.LocalDate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.MappedSuperclass;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

/**
* Should not be referenced by the code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import java.time.Duration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

public enum Status {
LIVING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.jpa.postgresql;
package io.quarkus.it.jpa.postgresql.defaultpu;

import jakarta.persistence.Embeddable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${postgres.url}
quarkus.datasource.jdbc.max-size=8

quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql
quarkus.hibernate-orm.packages=io.quarkus.it.jpa.postgresql.defaultpu
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.database.generation.create-schemas=true
# Define non-default PU so that we can configure a custom JSON format mapper. The default PU is using the default mapper.
quarkus.hibernate-orm."other".datasource=<default>
quarkus.hibernate-orm."other".packages=io.quarkus.it.jpa.postgresql.otherpu
quarkus.hibernate-orm."other".database.generation=drop-and-create
quarkus.hibernate-orm."other".database.generation.create-schemas=true

#Necessary for assertions in JPAFunctionalityInGraalITCase:
quarkus.native.enable-reports=true

0 comments on commit a58edc4

Please sign in to comment.