Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loaded entity classes in hibernate from #1114 #1155

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,15 @@ public InputStream getResourceAsStream(String name) {

@Override
public URL getResource(String name) {
try {
for (VirtualFile vf : Play.javaPath) {
VirtualFile res = vf.child(name);
if (res != null && res.exists()) {
try {
return res.getRealFile().toURI().toURL();
}
}
if (Play.usePrecompiled) {
File file = Play.getFile("precompiled/java/" + name);
if (file.exists()) {
return file.toURI().toURL();
}
}
else if ("true".equals(Play.configuration.getProperty("play.bytecodeCache", "true"))) {
File f = new File(Play.tmpDir, "classes/" + name);
if (f.exists()) {
return f.toURI().toURL();
}
}
} catch (MalformedURLException ex) {
throw new UnexpectedException(ex);
}
}
}
return super.getResource(name);
}
Expand Down
19 changes: 11 additions & 8 deletions framework/src/play/db/jpa/JPAPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ public void onApplicationStart() {
JPQL.instance = new JPQL();
}

private List<String> entityClasses(String dbName) {
List<String> entityClasses = new ArrayList<>();
private List<Class> entityClasses(String dbName) {
List<Class> entityClasses = new ArrayList<>();

List<Class> classes = Play.classloader.getAnnotatedClasses(Entity.class);
for (Class<?> clazz : classes) {
if (clazz.isAnnotationPresent(Entity.class)) {
// Do we have a transactional annotation matching our dbname?
PersistenceUnit pu = clazz.getAnnotation(PersistenceUnit.class);
if (pu != null && pu.name().equals(dbName)) {
entityClasses.add(clazz.getName());
entityClasses.add(clazz);
} else if (pu == null && JPA.DEFAULT.equals(dbName)) {
entityClasses.add(clazz.getName());
entityClasses.add(clazz);
}
}
}
Expand All @@ -162,9 +162,9 @@ private List<String> entityClasses(String dbName) {
// Do we have a transactional annotation matching our dbname?
PersistenceUnit pu = clazz.getAnnotation(PersistenceUnit.class);
if (pu != null && pu.name().equals(dbName)) {
entityClasses.add(clazz.getName());
entityClasses.add(clazz);
} else if (pu == null && JPA.DEFAULT.equals(dbName)) {
entityClasses.add(clazz.getName());
entityClasses.add(clazz);
}
} catch (Exception e) {
Logger.warn(e, "JPA -> Entity not found: %s", entity);
Expand All @@ -184,8 +184,11 @@ protected EntityManagerFactory newEntityManagerFactory(String dbName, Configurat
}

protected PersistenceUnitInfoImpl persistenceUnitInfo(String dbName, Configuration dbConfig) {
return new PersistenceUnitInfoImpl(dbName,
entityClasses(dbName), mappingFiles(dbConfig), properties(dbName, dbConfig));
final List<Class> managedClasses = entityClasses(dbName);
final Properties properties = properties(dbName, dbConfig);
properties.put(org.hibernate.jpa.AvailableSettings.LOADED_CLASSES,managedClasses);
return new PersistenceUnitInfoImpl(dbName,
managedClasses, mappingFiles(dbConfig), properties);
}

private List<String> mappingFiles(Configuration dbConfig) {
Expand Down
9 changes: 5 additions & 4 deletions framework/src/play/db/jpa/PersistenceUnitInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

/**
* @author Vlad Mihalcea
Expand All @@ -24,7 +25,7 @@ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {

private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;

private final List<String> managedClassNames;
private final List<Class> managedClasses;
private final List<String> mappingFileNames;

private final Properties properties;
Expand All @@ -33,9 +34,9 @@ public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {

private DataSource nonJtaDataSource;

public PersistenceUnitInfoImpl(String persistenceUnitName, List<String> managedClassNames, List<String> mappingFileNames, Properties properties) {
public PersistenceUnitInfoImpl(String persistenceUnitName, List<Class> managedClasses, List<String> mappingFileNames, Properties properties) {
this.persistenceUnitName = persistenceUnitName;
this.managedClassNames = managedClassNames;
this.managedClasses = managedClasses;
this.mappingFileNames = mappingFileNames;
this.properties = properties;
}
Expand Down Expand Up @@ -96,7 +97,7 @@ public URL getPersistenceUnitRootUrl() {

@Override
public List<String> getManagedClassNames() {
return managedClassNames;
return managedClasses.stream().map(Class::getName).collect(Collectors.toList());
}

@Override
Expand Down