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

ClassInfo.addIndexes() doesn't use MetaDataClassLoader.loadClass() instead of Class.forName() #314

Closed
gauravdingolia opened this issue Dec 30, 2016 · 2 comments

Comments

@gauravdingolia
Copy link

No description provided.

@gauravdingolia gauravdingolia changed the title addIndexes() doesn't use MetaDataClassLoader.loadClass() instead of Class.forName() ClassInfo.addIndexes() doesn't use MetaDataClassLoader.loadClass() instead of Class.forName() Dec 30, 2016
@mangrish
Copy link
Contributor

@gauravdingolia : Could you provide more detail? Versions, stack traces, sample code etc.

@gauravdingolia
Copy link
Author

gauravdingolia commented Dec 30, 2016

private Map<String, FieldInfo> addIndexes() {
        Map<String, FieldInfo> indexes = new HashMap<>();

        // No way to get declared fields from current byte code impl. Using reflection instead.
        Field[] declaredFields;
        try {
            declaredFields = Class.forName(className).getDeclaredFields();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not reflectively read declared fields", e);
        }

        final String indexAnnotation = Index.class.getCanonicalName();

        for (FieldInfo fieldInfo : fieldsInfo().fields()) {
            if (isDeclaredField(declaredFields, fieldInfo.getName()) && fieldInfo.hasAnnotation(indexAnnotation)) {
                indexes.put(fieldInfo.property(), fieldInfo);
            }
        }
        return indexes;
    }

Source from ClassInfo.java 2.1.0

When using neo4j ogm with play 2.5, there is a problem while instantiating SessionFactory.

    java.lang.ClassNotFoundException: models.neo4j.nodes.Person
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.neo4j.ogm.metadata.ClassInfo.addIndexes(ClassInfo.java:1267)
at org.neo4j.ogm.metadata.ClassInfo.getIndexFields(ClassInfo.java:1256)
at org.neo4j.ogm.metadata.ClassInfo.containsIndexes(ClassInfo.java:1248)
at org.neo4j.ogm.autoindex.AutoIndexManager.initialiseIndexMetadata(AutoIndexManager.java:71)
at org.neo4j.ogm.autoindex.AutoIndexManager.<init>(AutoIndexManager.java:58)

When I dig down to the source, turns out that ClassInfo.addIndex() is still using Class.forName instead of MetaDataClassLoader.loadClass().

Please correct me if I am missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants