This is the enable lazy load plugin
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<configuration>
<!--<failOnError>true</failOnError>-->
<enableLazyInitialization>true</enableLazyInitialization>
<!--<enableDirtyTracking>true</enableDirtyTracking>-->
<!--<enableAssociationManagement>true</enableAssociationManagement>-->
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Hibernate java based config properties are as folows
private Properties hibernateProperties(DataSourceConfiguration dataSourceConfiguration) {
Properties properties = new Properties();
// properties.setProperty("hibernate.hbm2ddl.auto", dataSourceConfiguration.getDdlGeneration());
properties.put("hibernate.dialect", dataSourceConfiguration.getDialect());
properties.put("hibernate.enable_lazy_load_no_trans", true);
properties.put("hibernate.jpa.compliance.transaction", true);
properties.put("hibernate.jpa.compliance.query", true);
properties.put("hibernate.jdbc.batch_size", 30);
properties.put("hibernate.order_inserts", true);
properties.put("hibernate.jdbc.batch_versioned_data", true);
properties.put("hibernate.ejb.use_class_enhancer",true);
properties.put("hibernate.enhancer.enableLazyInitialization",true);
// properties.setProperty("hibernate.enhancer.enableAssociationManagement","true");
properties.put("hibernate.current_session_context_class", dataSourceConfiguration.getCurrentSession());
properties.put("hibernate.show_sql", dataSourceConfiguration.getShowsql());
properties.put("hibernate.format_sql", dataSourceConfiguration.getFormatsql());
properties.put("hibernate.discriminator.ignore_explicit_for_joined", "true");
return properties;
}
and this is the persistance.xml
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> org.hibernate.jpa.HibernatePersistenceProvider
<non-jta-data-source></non-jta-data-source>
<properties>
<!--<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hcs?useSSL=false"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>-->
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/hcs?useSSL=false"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<!--<property name="spring.jpa.properties.hibernate.ejb.use_class_enhancer" value="true"/>-->
<!--<property name="hibernate.enhancer.enableLazyInitialization" value="true"/>-->
<!-- <property name="hibernate.hbm2ddl.auto" value="validate"/>-->
<property name="hibernate.discriminator.ignore_explicit_for_joined" value="true"/>
</properties>
</persistence-unit>
</persistence>
At runtime i am getting the below exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.orsbv.hcs.config.HCSRepositoryContext: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation. at org.springframework.util.Assert.state(Assert.java:73) at org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer(InstrumentationLoadTimeWeaver.java:89) at org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:85) at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.pushClassTransformer(PersistenceUnitInfoDescriptor.java:113) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:251) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.(EntityManagerFactoryBuilderImpl.java:164) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:51)