From 42b16591ec9978f9e317035bad998e617e79bb7e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 3 Jan 2023 11:55:33 +0100 Subject: [PATCH] SpringPersistenceUnitInfo leniently ignores transformer if no LoadTimeWeaver is present Closes gh-29736 --- .../persistenceunit/SpringPersistenceUnitInfo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java index da5e46fdbd8..fdb5765e0c3 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.orm.jpa.persistenceunit; import jakarta.persistence.spi.ClassTransformer; +import org.apache.commons.logging.LogFactory; import org.springframework.core.DecoratingClassLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; @@ -79,10 +80,12 @@ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { */ @Override public void addTransformer(ClassTransformer classTransformer) { - if (this.loadTimeWeaver == null) { - throw new IllegalStateException("Cannot apply class transformer without LoadTimeWeaver specified"); + if (this.loadTimeWeaver != null) { + this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer)); + } + else { + LogFactory.getLog(getClass()).info("No LoadTimeWeaver setup: ignoring JPA class transformer"); } - this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer)); } /**