Это плагин для отложенной загрузки
<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 приведены ниже.
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;
}
и это файл 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>
Во время выполнения я получаю следующее исключение
org.springframework.beans.factory.BeanCreationException: Ошибка при создании компонента с именем entityManagerFactory, определенным в com.orsbv.hcs.config.HCSRepositoryContext: сбой вызова метода init; Вложенное исключение - java.lang.IllegalStateException: должно начинаться с агента Java, чтобы использовать InstrumentationLoadTimeWeaver. Смотрите документацию Spring.
в org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1704)
в org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:583)
в org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:502)
в org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0 (AbstractBeanFactory.java:312)
в org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:228)
в org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:310)
в org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:200)
в org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1083)
в org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:858)
в org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:549)
в org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext (ContextLoader.java:409)
в org.springframework.web.context.ContextLoader.initWebApplicationContext (ContextLoader.java:291)
в org.springframework.web.context.ContextLoaderListener.contextInitialized (ContextLoaderListener.java:103)
в org.apache.catalina.core.StandardContext.listenerStart (StandardContext.java:4939)
в org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5434)
в org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150)
в org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1559)
в org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1549)
в java.util.concurrent.FutureTask.run (FutureTask.java:266)
в java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
в java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:624)
на java.lang.Thread.run (Thread.java:748)
Причина: java.lang.IllegalStateException: Должно начинаться с агента Java, чтобы использовать InstrumentationLoadTimeWeaver. Смотрите документацию Spring.
в org.springframework.util.Assert.state (Assert.java:73)
в org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer (InstrumentationLoadTimeWeaver.java:89)
в org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer (SpringPersistenceUnitInfo.java:85)
в org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.pushClassTransformer (PersistenceUnitInfoDescriptor.java:113)
в org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl. (EntityManagerFactoryBuilderImpl.java:251)
в org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl. (EntityManagerFactoryBuilderImpl.java:164)в org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory (SpringHibernateJpaPersistenceProvider.java:51)