2
  1. Involve the https://plugins.gradle.org/plugin/org.jamgo.eclipselink-plugin
  2. Check the log [EL Warning]: metadata: ServerSession(1559673372)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [copyCustomer] for the entity class [class com.hybris.caas.order.model.Order] since weaving was not enabled or did not occur.
   @Configuration
public class JpaConfig extends JpaBaseConfiguration {

   protected JpaConfig(DataSource dataSource, JpaProperties properties,
                       ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
                       ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
       super(dataSource, properties, jtaTransactionManagerProvider, transactionManagerCustomizers);
   }

   @Override
   protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
       return new EclipseLinkJpaVendorAdapter();
   }

   @Override
   protected Map<String, Object> getVendorProperties() {
       final HashMap<String, Object> props = new HashMap<>();
       props.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
       return props;
   }

   private String detectWeavingMode() {
       return "static";
   }

   /**
    *
    * @param entityManagerFactory
    * @return
    */
   @Bean
   public PlatformTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) {
       final JpaTransactionManager transactionManager = new JpaTransactionManager();
       transactionManager.setEntityManagerFactory(entityManagerFactory);
       return transactionManager;
   }

}
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.jamgo:eclipselink-plugin:0.2.2"
  }
}

apply plugin: "org.jamgo.eclipselink-plugin"

Allen Wu
  • 21
  • 1

1 Answers1

0

I'm not sure about this plugin and it's capabilities but this is possible with pure Gradle without plugins.

There are 3 steps to do in order to make this work:

  • Copy the persistence.xml file into the source folder next to the classes
  • Do the weaving
  • Remove the persistence.xml file from the classes source folder to avoid duplicate persistence.xml conflicts on the classpath

Also, it's very important to hook the process up into the compileJava task's last step in order to not break Gradle's up-to-date check.

For a more detailed explanation, check out my article on it: EclipseLink static weaving with Gradle.

Arnold Galovics
  • 3,246
  • 3
  • 22
  • 33