SpringPersistenceUnitInfo leniently ignores transformer if no LoadTimeWeaver is present

Closes gh-29736
This commit is contained in:
Juergen Hoeller 2023-01-03 11:55:33 +01:00
parent 62cf2f0a4f
commit 42b16591ec
1 changed files with 7 additions and 4 deletions

View File

@ -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));
}
/**