Skip to content

Commit

Permalink
fix pull #1114
Browse files Browse the repository at this point in the history
  • Loading branch information
flybyray committed May 29, 2017
1 parent 0c59058 commit c53b262
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
18 changes: 3 additions & 15 deletions framework/src/play/classloading/ApplicationClassloader.java
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
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
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

0 comments on commit c53b262

Please sign in to comment.