Browse Source
Includes fix for consistent PersistenceException in case of no unit found for name. Includes proper tests for Local(Container)EntityManagerFactoryBean with scan setup. Closes gh-36270 Closes gh-36271pull/36281/head
21 changed files with 393 additions and 21 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright 2002-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.eclipselink; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
class EclipseLinkEntityManagerFactoryScanIntegrationTests extends EclipseLinkEntityManagerFactoryIntegrationTests { |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return new String[] {"/org/springframework/orm/jpa/eclipselink/eclipselink-manager-scan.xml", |
||||
"/org/springframework/orm/jpa/memdb.xml", "/org/springframework/orm/jpa/inject.xml"}; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2002-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.eclipselink; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
class EclipseLinkEntityManagerFactorySimpleIntegrationTests extends EclipseLinkEntityManagerFactoryIntegrationTests { |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return new String[] {"/org/springframework/orm/jpa/eclipselink/eclipselink-manager-simple.xml", |
||||
"/org/springframework/orm/jpa/memdb.xml", "/org/springframework/orm/jpa/inject.xml"}; |
||||
} |
||||
|
||||
@Test |
||||
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() { |
||||
assertThat(entityManagerFactory).isInstanceOf(EntityManagerFactoryInfo.class); |
||||
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; |
||||
assertThat(emfi.getPersistenceUnitName()).isEqualTo("Person"); |
||||
assertThat(emfi.getPersistenceUnitInfo()).as("PersistenceUnitInfo must not be used").isNull(); |
||||
assertThat(emfi.getNativeEntityManagerFactory()).as("Raw EntityManagerFactory must be available").isNotNull(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright 2002-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.hibernate; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
class HibernateEntityManagerFactoryScanIntegrationTests extends HibernateEntityManagerFactoryIntegrationTests { |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return new String[] {"/org/springframework/orm/jpa/hibernate/hibernate-manager-scan.xml", |
||||
"/org/springframework/orm/jpa/memdb.xml", "/org/springframework/orm/jpa/inject.xml"}; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2002-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.orm.jpa.hibernate; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
class HibernateEntityManagerFactorySimpleIntegrationTests extends HibernateEntityManagerFactoryIntegrationTests { |
||||
|
||||
@Override |
||||
protected String[] getConfigLocations() { |
||||
return new String[] {"/org/springframework/orm/jpa/hibernate/hibernate-manager-simple.xml", |
||||
"/org/springframework/orm/jpa/memdb.xml", "/org/springframework/orm/jpa/inject.xml"}; |
||||
} |
||||
|
||||
@Test |
||||
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() { |
||||
assertThat(entityManagerFactory).isInstanceOf(EntityManagerFactoryInfo.class); |
||||
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; |
||||
assertThat(emfi.getPersistenceUnitName()).isEqualTo("Person"); |
||||
assertThat(emfi.getPersistenceUnitInfo()).as("PersistenceUnitInfo must not be used").isNull(); |
||||
assertThat(emfi.getNativeEntityManagerFactory()).as("Raw EntityManagerFactory must be available").isNotNull(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> |
||||
<qualifier type="org.springframework.orm.jpa.domain.MyDomain"/> |
||||
<property name="persistenceUnitName" value="Person"/> |
||||
<property name="packagesToScan" value="org.springframework.orm.jpa.domain*"/> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
<property name="jpaVendorAdapter"> |
||||
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
</property> |
||||
<property name="jpaPropertyMap"> |
||||
<props> |
||||
<prop key="eclipselink.weaving">false</prop> |
||||
</props> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> |
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> |
||||
<qualifier type="org.springframework.orm.jpa.domain.MyDomain"/> |
||||
<property name="persistenceUnitName" value="Person"/> |
||||
<property name="packagesToScan" value="org.springframework.orm.jpa.domain*"/> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
<property name="jpaVendorAdapter"> |
||||
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
</property> |
||||
<property name="jpaPropertyMap"> |
||||
<props> |
||||
<prop key="eclipselink.weaving">false</prop> |
||||
</props> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> |
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" primary="true"> |
||||
<qualifier type="org.springframework.orm.jpa.domain.MyDomain"/> |
||||
<property name="persistenceUnitName" value="Person"/> |
||||
<property name="packagesToScan" value="org.springframework.orm.jpa.domain*"/> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
<property name="jpaVendorAdapter"> |
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
</property> |
||||
<property name="jpaPropertyMap"> |
||||
<props> |
||||
<prop key="hibernate.current_session_context_class">org.springframework.orm.jpa.hibernate.SpringSessionContext</prop> |
||||
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop> |
||||
</props> |
||||
</property> |
||||
<property name="bootstrapExecutor"> |
||||
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> |
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/> |
||||
</bean> |
||||
|
||||
<bean id="hibernateStatistics" factory-bean="entityManagerFactory" factory-method="getStatistics" lazy-init="true"/> |
||||
|
||||
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> |
||||
|
||||
<bean class="org.springframework.aop.support.DefaultPointcutAdvisor"> |
||||
<property name="pointcut"><bean class="org.springframework.orm.jpa.EntityManagerPointcut"/></property> |
||||
<property name="advice"><bean class="org.springframework.aop.interceptor.SimpleTraceInterceptor"/></property> |
||||
</bean> |
||||
|
||||
</beans> |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" primary="true"> |
||||
<qualifier type="org.springframework.orm.jpa.domain.MyDomain"/> |
||||
<property name="persistenceUnitName" value="Person"/> |
||||
<property name="packagesToScan" value="org.springframework.orm.jpa.domain*"/> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
<property name="jpaVendorAdapter"> |
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> |
||||
<property name="database" value="HSQL"/> |
||||
<property name="showSql" value="true"/> |
||||
<property name="generateDdl" value="true"/> |
||||
</bean> |
||||
</property> |
||||
<property name="jpaPropertyMap"> |
||||
<props> |
||||
<prop key="hibernate.current_session_context_class">org.springframework.orm.jpa.hibernate.SpringSessionContext</prop> |
||||
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop> |
||||
</props> |
||||
</property> |
||||
<property name="bootstrapExecutor"> |
||||
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/> |
||||
</property> |
||||
</bean> |
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> |
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/> |
||||
</bean> |
||||
|
||||
<bean id="hibernateStatistics" factory-bean="entityManagerFactory" factory-method="getStatistics" lazy-init="true"/> |
||||
|
||||
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> |
||||
|
||||
<bean class="org.springframework.aop.support.DefaultPointcutAdvisor"> |
||||
<property name="pointcut"><bean class="org.springframework.orm.jpa.EntityManagerPointcut"/></property> |
||||
<property name="advice"><bean class="org.springframework.aop.interceptor.SimpleTraceInterceptor"/></property> |
||||
</bean> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue