Skip to content

Commit

Permalink
SpringPersistenceUnitInfo leniently ignores transformer if no LoadTim…
Browse files Browse the repository at this point in the history
…eWeaver is present

Closes gh-29736
  • Loading branch information
jhoeller committed Jan 3, 2023
1 parent 62cf2f0 commit 42b1659
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -79,10 +80,12 @@ public ClassLoader getClassLoader() {
*/
@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));
}

/**
Expand Down

0 comments on commit 42b1659

Please sign in to comment.