Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private ByteBuddyProxyHelper getByteBuddyProxyHelper() {
public boolean isProxiable(ClassInfo classInfo) {
return classInfo != null
&& !classInfo.isInterface()
&& !classInfo.isAbstract()
&& !classInfo.isFinal()
&& classInfo.hasNoArgsConstructor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public void postInstantiate(String entityName, Class<?> persistentClass, Set<Cla
else if (Modifier.isFinal(persistentClass.getModifiers())) {
reason = "this class is final. Your application might perform better if this class was non-final.";
}
if (Modifier.isAbstract(persistentClass.getModifiers())) {
reason = "this class is abstract. Your application might perform better if this class was non-abstract.";
}
if (reason != null) {
// This is caught and logged as a warning by Hibernate ORM.
throw new HibernateException(String.format(Locale.ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.hibernate.proxy.HibernateProxy;

import io.quarkus.narayana.jta.QuarkusTransaction;
import io.quarkus.narayana.jta.runtime.TransactionConfiguration;
import io.quarkus.runtime.StartupEvent;
Expand Down Expand Up @@ -78,6 +80,18 @@ public String testBasic() {
return "OK";
}

@GET
@Path("abstract")
@Transactional
public String testAbstract() {
var result = entityManager.getReference(AbstractEntity.class, "1");
expectTrue(result != null);
expectTrue(result instanceof HibernateProxy);
// Make sure we don't get fooled by some kind of "fallback" eager loading
expectFalse(result instanceof ConcreteEntity);
return "OK";
}

/**
* tests for the @Proxy annotation in an inheritance hierarchy
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package io.quarkus.it.jpa.proxy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.LogCollectingTestResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.ResourceArg;
import io.quarkus.test.junit.DisabledOnIntegrationTest;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
@QuarkusTestResource(value = LogCollectingTestResource.class, restrictToAnnotatedClass = true, initArgs = {
@ResourceArg(name = LogCollectingTestResource.LEVEL, value = "WARNING"),
@ResourceArg(name = LogCollectingTestResource.INCLUDE, value = "org\\.hibernate\\..*"),
// Ignore logs about schema management:
// they are unfortunate (https://github.com/quarkusio/quarkus/issues/16204)
// but for now we have to live with them.
@ResourceArg(name = LogCollectingTestResource.EXCLUDE, value = "org\\.hibernate\\.tool\\.schema.*")
})
public class ProxyTest {

@Test
Expand All @@ -25,4 +38,26 @@ public void testEnhancedProxies() {
RestAssured.when().get("/jpa-test/proxy/enhanced").then().body(is("OK"));
}

@Test
public void testAbstractClassProxies() {
RestAssured.when().get("/jpa-test/proxy/abstract").then().body(is("OK"));
}

@Test
// When running as integration test, we cannot easily spy on logs.
@DisabledOnIntegrationTest
public void testProxyWarningsOnStartup() {
assertThat(LogCollectingTestResource.current().getRecords())
// There shouldn't be any warning or error
.as("Startup logs (warning or higher)")
.extracting(LogCollectingTestResource::format)
.satisfiesExactlyInAnyOrder(
// Final classes cannot be proxied
m -> assertThat(m).contains(
"Could not create proxy factory", CompanyCustomer.class.getName(),
"this class is final", "Your application might perform better if this class was non-final.")
// Importantly, we don't expect any other warning about proxies!
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LogCollectingTestResource implements QuarkusTestResourceLifecycleMa
public static final String EXCLUDE = "exclude";
public static final String INCLUDE = "include";

private static final Formatter LOG_FORMATTER = new PatternFormatter("%s");
private static final Formatter LOG_FORMATTER = new PatternFormatter("%m");

public static String format(LogRecord record) {
return LOG_FORMATTER.format(record);
Expand Down
Loading