1

Project uses:

  • spring boot 2.1.1

  • oracle 12 database

  • eclipselink 2.6.5

  • maven 3.6.0

in this project we are using a provided jar with the entities and we created the configuration withouth persistence.xml. The project is created as a war to be deployed in weblogic 12c server but we are testing with springboot inbuilt tomcat server. And ocasionaly on a test server with Weblogic.

When we launch the application in either container we get a lot of EL warnings like the following one:

[EL Warning]: metadata: 2019-02-28 17:10:14.684--ServerSession(1764986459)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [readonlyUserInformation] for the entity class [class com.adquira.mkp.persistence.entities.auditory.AuditoryEvent] since weaving was not enabled or did not occur.

after searching and looking everywhere how to solve this the only similar question we found was this question about static weaving not working in springboot

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.adus</groupId>
    <artifactId>adus-backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>adus-backend</name>
    <description>Adus back-end development</description>

    <properties>
        <java.version>1.8</java.version>
        <springfox-swagger.version>2.9.2</springfox-swagger.version>
        <eclipselink.version>2.6.5</eclipselink.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.adquira.orm</groupId>
            <artifactId>adquira-orm</artifactId>
            <version>1.0.20</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0.2</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>   
        <!-- swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox-swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox-swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.core</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

The class for configuration

package com.adus.adusbackend;

import java.util.Properties;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;


@Configuration
@EnableJpaRepositories(basePackages = { "com.adus.adusbackend.repository.user","com.adus.adusbackend.repository.market"})
public class DatasourceConfiguration  {

    @Bean(destroyMethod = "close")
    @ConfigurationProperties(prefix = "spring.datasource")
      public DataSource dataSource() {
        return DataSourceBuilder.create().build();
      }

    @Bean
    EclipseLinkJpaVendorAdapter jpaVendorAdapter() {
        EclipseLinkJpaVendorAdapter jpaVendorAdapter = new EclipseLinkJpaVendorAdapter();
        jpaVendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.oracle.Oracle12Platform");
        jpaVendorAdapter.setGenerateDdl(Boolean.FALSE);
        jpaVendorAdapter.setShowSql(Boolean.TRUE);

        return jpaVendorAdapter;
    }

    @Bean
    LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setDataSource(dataSource);
        entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter());
        entityManagerFactoryBean.setJpaDialect(new EclipseLinkJpaDialect());

        // Instead of persistence.xml
        entityManagerFactoryBean.setPersistenceUnitName("des");
        entityManagerFactoryBean.setPackagesToScan("com.adquira.mkp.persistence.entities");

        Properties jpaProperties = new Properties();
        jpaProperties.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
        jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION, "none");
        entityManagerFactoryBean.setJpaProperties(jpaProperties);

        entityManagerFactoryBean.afterPropertiesSet();

        return entityManagerFactoryBean;
    }

    @Bean
    JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        return transactionManager;
    }

    private String detectWeavingMode() {
        return InstrumentationLoadTimeWeaver.isInstrumentationAvailable() ? "true" : "static";
    }
}

1 Answer 1

1

You have two challenges.

Firstly: to have static weaving to happen at all and entities enhanced you need a properly configured maven plugin to do that. You need to add weaver plugin to your plugin section. Example from Eclipselink Wiki-page:

<plugins>
    ...
    <plugin>
        <groupId>de.empulse.eclipselink</groupId>
        <artifactId>staticweave-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>weave</goal>
                </goals>
                <configuration>
                    <persistenceXMLLocation>
                        META-INF/persistence.xml</persistenceXMLLocation>
                    <logLevel>FINE</logLevel>
                </configuration>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>org.eclipse.persistence.jpa</artifactId>
                <version>${eclipselink.version}</version>
            </dependency>
        </dependencies>
    </plugin>
    ...
</plugins>

Secondly: you need to make plugin aware the classes in external jar. There were quite few articles about that and I am not sure if it is even possible (easily). The wiki page mentions only about sources to weave which can be in a jar but does not directly say if it is possible also for compiled classes.

For this reason I have always made my entity library jars readily enhanced when compiled from source. But anyway there are some related posts like this.

3
  • 2
    My problem so to speak, is that i don't have an persistence.xml, everything is anotation based and because this is a war file i can't reference external entities in a jar because they live in different parts of the target
    – xerido
    Commented Mar 1, 2019 at 9:19
  • @xerido Yes. But actually for weaving you can add a persistence.xml file only for that, having just the needed information for weaver. I remember doing that when generated jars having only enhanced entities. But for ready jars having entiteis do not know if it is possible still.
    – pirho
    Commented Mar 1, 2019 at 9:47
  • 1
    In the end talking with the client about the problems and solutions we got an preweaved with included persistence jar. anyways part of your solution is still correct ( we made it possible to make some clases weaved)
    – xerido
    Commented Mar 7, 2019 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.