Re-enable Hibernate EntityManagerFactory tests
HibernateEntityManagerFactoryIntegrationTests in the spring-orm module has been disabled for quite some time due to a dependency on the AnnotationBeanConfigurerAspect from the spring-aspects module. Since spring-aspects depends on spring-orm, a cyclical dependency would result if this code were re-enabled "as is". This commit removes the dependency on AnnotationBeanConfigurerAspect in HibernateEntityManagerFactoryIntegrationTests by deleting all test code and configuration related to @Configurable. In addition, this commit also deletes all SessionFactory-specific test code in HibernateEntityManagerFactoryIntegrationTests, allowing the test class to focus on Hibernate as a JPA provider. Issue: SPR-11922
This commit is contained in:
parent
476864f3e9
commit
32b87079cb
|
@ -165,12 +165,6 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testAspectJInjectionOfConfigurableEntity() {
|
|
||||||
// Person p = new Person();
|
|
||||||
// assertNotNull("Was injected", p.getTestBean());
|
|
||||||
// assertEquals("Ramnivas", p.getTestBean().getName());
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void testInstantiateAndSaveWithSharedEmProxy() {
|
public void testInstantiateAndSaveWithSharedEmProxy() {
|
||||||
testInstantiateAndSave(sharedEntityManager);
|
testInstantiateAndSave(sharedEntityManager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2013 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
|
|
||||||
*
|
|
||||||
* http://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.domain;
|
|
||||||
|
|
||||||
import javax.persistence.Basic;
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.OneToOne;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
|
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
@Configurable
|
|
||||||
public class ContextualPerson {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
private transient TestBean testBean;
|
|
||||||
|
|
||||||
// Lazy relationship to force use of instrumentation in JPA implementation.
|
|
||||||
@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
|
|
||||||
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
|
||||||
private DriversLicense driversLicense;
|
|
||||||
|
|
||||||
private String first_name;
|
|
||||||
|
|
||||||
@Basic(fetch=FetchType.LAZY)
|
|
||||||
private String last_name;
|
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
public transient EntityManager entityManager;
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTestBean(TestBean testBean) {
|
|
||||||
this.testBean = testBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestBean getTestBean() {
|
|
||||||
return testBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
|
||||||
this.first_name = firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstName() {
|
|
||||||
return this.first_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.last_name = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return this.last_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDriversLicense(DriversLicense driversLicense) {
|
|
||||||
this.driversLicense = driversLicense;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DriversLicense getDriversLicense() {
|
|
||||||
return this.driversLicense;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getClass().getName() + ":(" + hashCode() + ") id=" + id +
|
|
||||||
"; firstName=" + first_name + "; lastName=" + last_name + "; testBean=" + testBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -27,7 +27,6 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
|
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple JavaBean domain object representing an person.
|
* Simple JavaBean domain object representing an person.
|
||||||
|
@ -35,23 +34,22 @@ import org.springframework.beans.factory.annotation.Configurable;
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Configurable
|
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private transient TestBean testBean;
|
private transient TestBean testBean;
|
||||||
|
|
||||||
// Lazy relationship to force use of instrumentation in JPA implementation.
|
// Lazy relationship to force use of instrumentation in JPA implementation.
|
||||||
@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
|
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
|
||||||
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
@JoinColumn(name = "DRIVERS_LICENSE_ID")
|
||||||
private DriversLicense driversLicense;
|
private DriversLicense driversLicense;
|
||||||
|
|
||||||
private String first_name;
|
private String first_name;
|
||||||
|
|
||||||
@Basic(fetch=FetchType.LAZY)
|
@Basic(fetch = FetchType.LAZY)
|
||||||
private String last_name;
|
private String last_name;
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,11 +89,10 @@ public class Person {
|
||||||
return this.driversLicense;
|
return this.driversLicense;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getName() + ":(" + hashCode() + ") id=" + id +
|
return getClass().getName() + ":(" + hashCode() + ") id=" + id + "; firstName=" + first_name + "; lastName="
|
||||||
"; firstName=" + first_name + "; lastName=" + last_name + "; testBean=" + testBean;
|
+ last_name + "; testBean=" + testBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||||
version="1.0">
|
version="1.0">
|
||||||
|
|
||||||
<persistence-unit name="Person" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="Person" transaction-type="RESOURCE_LOCAL">
|
||||||
<class>org.springframework.orm.jpa.domain.ContextualPerson</class>
|
|
||||||
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
||||||
<class>org.springframework.orm.jpa.domain.Person</class>
|
<class>org.springframework.orm.jpa.domain.Person</class>
|
||||||
<exclude-unlisted-classes/>
|
<exclude-unlisted-classes />
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||||
version="1.0">
|
version="1.0">
|
||||||
|
|
||||||
<persistence-unit name="Drivers" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="Drivers" transaction-type="RESOURCE_LOCAL">
|
||||||
<class>org.springframework.orm.jpa.domain.Person</class>
|
<class>org.springframework.orm.jpa.domain.Person</class>
|
||||||
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
||||||
<exclude-unlisted-classes/>
|
<exclude-unlisted-classes />
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
<persistence-unit name="Test" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="Test" transaction-type="RESOURCE_LOCAL">
|
||||||
<class>org.springframework.tests.sample.beans.TestBean</class>
|
<class>org.springframework.tests.sample.beans.TestBean</class>
|
||||||
<exclude-unlisted-classes/>
|
<exclude-unlisted-classes />
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||||
version="1.0">
|
version="1.0">
|
||||||
|
|
||||||
<persistence-unit name="Person" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="Person" transaction-type="RESOURCE_LOCAL">
|
||||||
<class>org.springframework.orm.jpa.domain.Person</class>
|
<class>org.springframework.orm.jpa.domain.Person</class>
|
||||||
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
<class>org.springframework.orm.jpa.domain.DriversLicense</class>
|
||||||
<exclude-unlisted-classes/>
|
<exclude-unlisted-classes />
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -16,16 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.orm.jpa.hibernate;
|
package org.springframework.orm.jpa.hibernate;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.Query;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;
|
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;
|
||||||
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
|
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
|
||||||
import org.springframework.orm.jpa.domain.Person;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate-specific JPA tests.
|
* Hibernate-specific JPA tests.
|
||||||
|
@ -33,25 +27,10 @@ import org.springframework.orm.jpa.domain.Person;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
*/
|
*/
|
||||||
// TODO [SPR-11922] Decide what to do with HibernateEntityManagerFactoryIntegrationTests.
|
|
||||||
@Ignore("Disabled since AnnotationBeanConfigurerAspect cannot be found")
|
|
||||||
// The reason AnnotationBeanConfigurerAspect cannot be found is that it resides
|
|
||||||
// in the spring-aspects module which depends on this module (spring-orm). Thus,
|
|
||||||
// in order to overcome the cyclical dependency, this test could be moved to the
|
|
||||||
// root 'spring' module as a framework-level integration test, but the challenge
|
|
||||||
// with doing so is that this class depends on a test class hierarchy which is
|
|
||||||
// defined in this module.
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class HibernateEntityManagerFactoryIntegrationTests extends
|
public class HibernateEntityManagerFactoryIntegrationTests extends
|
||||||
AbstractContainerEntityManagerFactoryIntegrationTests {
|
AbstractContainerEntityManagerFactoryIntegrationTests {
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
|
||||||
|
|
||||||
|
|
||||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
|
||||||
this.sessionFactory = sessionFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getConfigLocations() {
|
protected String[] getConfigLocations() {
|
||||||
return HIBERNATE_CONFIG_LOCATIONS;
|
return HIBERNATE_CONFIG_LOCATIONS;
|
||||||
|
@ -68,22 +47,4 @@ public class HibernateEntityManagerFactoryIntegrationTests extends
|
||||||
assertNotNull(hibernateEntityManager.getSession());
|
assertNotNull(hibernateEntityManager.getSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithHibernateSessionFactory() {
|
|
||||||
// Add with JDBC
|
|
||||||
String firstName = "Tony";
|
|
||||||
insertPerson(firstName);
|
|
||||||
|
|
||||||
Query q = this.sessionFactory.getCurrentSession().createQuery("select p from Person as p");
|
|
||||||
List<Person> people = q.list();
|
|
||||||
|
|
||||||
assertEquals(1, people.size());
|
|
||||||
assertEquals(firstName, people.get(0).getFirstName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConfigurablePerson() {
|
|
||||||
Query q = this.sessionFactory.getCurrentSession().createQuery("select p from ContextualPerson as p");
|
|
||||||
assertEquals(0, q.list().size());
|
|
||||||
// assertNotNull(new ContextualPerson().entityManager); TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +1,30 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
xsi:schemaLocation="
|
xsi:schemaLocation="
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
|
||||||
<context:load-time-weaver aspectj-weaving="on"/>
|
<context:load-time-weaver aspectj-weaving="on" />
|
||||||
|
|
||||||
<context:annotation-config/>
|
<context:annotation-config />
|
||||||
|
|
||||||
<context:spring-configured/>
|
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||||
|
<property name="persistenceXmlLocation" value="org/springframework/orm/jpa/domain/persistence-context.xml" />
|
||||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
|
<property name="dataSource" ref="dataSource" />
|
||||||
depends-on="org.springframework.context.config.internalBeanConfigurerAspect">
|
|
||||||
<property name="persistenceXmlLocation" value="org/springframework/orm/jpa/domain/persistence-context.xml"/>
|
|
||||||
<property name="dataSource" ref="dataSource"/>
|
|
||||||
<property name="jpaVendorAdapter">
|
<property name="jpaVendorAdapter">
|
||||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||||
<property name="database" value="HSQL"/>
|
<property name="database" value="HSQL" />
|
||||||
<property name="showSql" value="true"/>
|
<property name="showSql" value="true" />
|
||||||
<property name="generateDdl" value="true"/>
|
<property name="generateDdl" value="true" />
|
||||||
</bean>
|
</bean>
|
||||||
</property>
|
</property>
|
||||||
<property name="jpaPropertyMap">
|
<property name="jpaPropertyMap">
|
||||||
<props>
|
<props>
|
||||||
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
|
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
|
||||||
<!--
|
<!-- <prop key="hibernate.ejb.use_class_enhancer">true</prop> -->
|
||||||
<prop key="hibernate.ejb.use_class_enhancer">true</prop>
|
|
||||||
-->
|
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
|
|
||||||
<property name="dataSource" ref="dataSource"/>
|
|
||||||
<property name="packagesToScan" value="org.springframework.orm.jpa.domain"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
Loading…
Reference in New Issue