Skip to content

Commit 3869845

Browse files
committed
HHH-8364 test case
1 parent d9310b1 commit 3869845

File tree

5 files changed

+220
-1
lines changed

5 files changed

+220
-1
lines changed

hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ private BootstrapServiceRegistry buildBootstrapServiceRegistry(Map integrationSe
509509
}
510510
else if ( appClassLoader != null ) {
511511
classLoader = appClassLoader;
512-
integrationSettings.remove( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
513512
}
514513
else {
515514
classLoader = persistenceUnit.getClassLoader();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.jpa.test.persistenceunit;
22+
23+
import javax.persistence.Entity;
24+
import javax.persistence.GeneratedValue;
25+
import javax.persistence.Id;
26+
27+
/**
28+
* @author Brett Meyer
29+
*/
30+
@Entity
31+
public class DataPoint {
32+
33+
@Id
34+
@GeneratedValue
35+
private long id;
36+
37+
public long getId() {
38+
return id;
39+
}
40+
41+
public void setId(long id) {
42+
this.id = id;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.jpa.test.persistenceunit;
22+
23+
import static org.junit.Assert.assertNull;
24+
import static org.junit.Assert.assertNotNull;
25+
26+
import java.io.IOException;
27+
import java.net.URL;
28+
import java.util.Enumeration;
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
32+
import javax.persistence.EntityManagerFactory;
33+
34+
import org.hibernate.cfg.AvailableSettings;
35+
import org.hibernate.internal.util.ConfigHelper;
36+
import org.hibernate.jpa.HibernatePersistenceProvider;
37+
import org.hibernate.testing.TestForIssue;
38+
import org.hibernate.testing.junit4.BaseUnitTestCase;
39+
import org.junit.Test;
40+
41+
/**
42+
* @author Brett Meyer
43+
*/
44+
@TestForIssue(jiraKey = "HHH-8364")
45+
public class ExcludeUnlistedClassesTest extends BaseUnitTestCase {
46+
47+
@Test
48+
public void testExcludeUnlistedClasses() {
49+
// see src/test/resources/org/hibernate/jpa/test/persistenceunit/persistence.xml
50+
doTest( "ExcludeUnlistedClassesTest1", true );
51+
doTest( "ExcludeUnlistedClassesTest2", false );
52+
doTest( "ExcludeUnlistedClassesTest3", true );
53+
doTest( "ExcludeUnlistedClassesTest4", false );
54+
}
55+
56+
private void doTest(String persistenceUnitName, boolean shouldScan) {
57+
final Map<String, Object> properties = new HashMap<String, Object>();
58+
properties.put( AvailableSettings.APP_CLASSLOADER, new TestClassLoader() );
59+
final HibernatePersistenceProvider provider = new HibernatePersistenceProvider();
60+
final EntityManagerFactory emf = provider.createEntityManagerFactory( persistenceUnitName, properties );
61+
assertNotNull( emf.getMetamodel().entity( DataPoint.class ) );
62+
if (shouldScan) {
63+
assertNull( emf.getMetamodel().entity( UnlistedDataPoint.class ) );
64+
}
65+
else {
66+
assertNotNull( emf.getMetamodel().entity( UnlistedDataPoint.class ) );
67+
}
68+
}
69+
70+
private static class TestClassLoader extends ClassLoader {
71+
72+
/**
73+
* testStoppableClassLoaderService() needs a custom JDK service implementation. Rather than using a real one
74+
* on the test classpath, force it in here.
75+
*/
76+
@Override
77+
protected Enumeration<URL> findResources(String name) throws IOException {
78+
if (name.equals( "META-INF/persistence.xml" )) {
79+
final URL puUrl = ConfigHelper.findAsResource(
80+
"org/hibernate/jpa/test/persistenceunit/META-INF/persistence.xml" );
81+
return new Enumeration<URL>() {
82+
boolean hasMore = true;
83+
84+
@Override
85+
public boolean hasMoreElements() {
86+
return hasMore;
87+
}
88+
89+
@Override
90+
public URL nextElement() {
91+
hasMore = false;
92+
return puUrl;
93+
}
94+
};
95+
}
96+
else {
97+
return java.util.Collections.emptyEnumeration();
98+
}
99+
}
100+
}
101+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* JBoss, Home of Professional Open Source
5+
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
6+
* as indicated by the @authors tag. All rights reserved.
7+
* See the copyright.txt in the distribution for a
8+
* full listing of individual contributors.
9+
*
10+
* This copyrighted material is made available to anyone wishing to use,
11+
* modify, copy, or redistribute it subject to the terms and conditions
12+
* of the GNU Lesser General Public License, v. 2.1.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT A
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
* You should have received a copy of the GNU Lesser General Public License,
17+
* v.2.1 along with this distribution; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
* MA 02110-1301, USA.
20+
*/
21+
package org.hibernate.jpa.test.persistenceunit;
22+
23+
import javax.persistence.Entity;
24+
import javax.persistence.GeneratedValue;
25+
import javax.persistence.Id;
26+
27+
/**
28+
* @author Brett Meyer
29+
*/
30+
@Entity
31+
public class UnlistedDataPoint {
32+
33+
@Id
34+
@GeneratedValue
35+
private long id;
36+
37+
public long getId() {
38+
return id;
39+
}
40+
41+
public void setId(long id) {
42+
this.id = id;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
5+
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
6+
version="2.1">
7+
8+
<persistence-unit name="ExcludeUnlistedClassesTest1" transaction-type="RESOURCE_LOCAL">
9+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
10+
<class>org.hibernate.jpa.test.persistenceunit.DataPoint</class>
11+
</persistence-unit>
12+
13+
<persistence-unit name="ExcludeUnlistedClassesTest2" transaction-type="RESOURCE_LOCAL">
14+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
15+
<class>org.hibernate.jpa.test.persistenceunit.DataPoint</class>
16+
<exclude-unlisted-classes/>
17+
</persistence-unit>
18+
19+
<persistence-unit name="ExcludeUnlistedClassesTest3" transaction-type="RESOURCE_LOCAL">
20+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
21+
<class>org.hibernate.jpa.test.persistenceunit.DataPoint</class>
22+
<exclude-unlisted-classes>false</exclude-unlisted-classes>
23+
</persistence-unit>
24+
25+
<persistence-unit name="ExcludeUnlistedClassesTest4" transaction-type="RESOURCE_LOCAL">
26+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
27+
<class>org.hibernate.jpa.test.persistenceunit.DataPoint</class>
28+
<exclude-unlisted-classes>true</exclude-unlisted-classes>
29+
</persistence-unit>
30+
31+
</persistence>

0 commit comments

Comments
 (0)