mhgrove / Empire

JPA implementation for RDF

Home Page:http://groups.google.com/group/empire-rdf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

find an instance of a class loaded with another ClassLoader

suricatec opened this issue · comments

The problem is that, when an object is loaded from the triplestore, if the class of this object can’t be reached by the current ClassLoader, an exception is throwing by javassist.
For example :

@entity
@RdfsClass("example:BusinessObject")
public class BusinessObject
{

@RdfId
private String uri;
@RdfProperty(DCTERMS.PREFIX + ":title")
private String title;
@RdfProperty("example:HadBusiness")
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
private Collection<Business> business = new LinkedList<Business>();

public BusinessObject() {

}

[…]
}

Where Business is an interface :

public abstract class Business extends BaseRdfEntity{

public abstract String getSubject();

public abstract void setSubject(String s);

}

If the collection contain an implementation of Business loaded by another ClassLoader :

@entity
@RdfsClass("example:BusinessForBO1")
public class BusinessForBO1 extends Business{

@RdfId
private String uri;
@RdfProperty(DCTERMS.PREFIX + ":subject")
private String subject;

public BusinessForBO1(){

}

[…]
}

A entityManager.find(BusinessObject.class, [URI]) to load an instance of BusinessObject cause the following trace :

Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Error converting a list value.
at module2.Module2.runModule(Unknown Source)
at main.Main.main(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Error converting a list value.
at com.clarkparsia.empire.annotation.RdfGenerator$ToObjectFunction.apply(RdfGenerator.java:998)
at com.clarkparsia.empire.annotation.RdfGenerator.fromRdf(RdfGenerator.java:477)
at com.clarkparsia.empire.annotation.RdfGenerator.fromRdf(RdfGenerator.java:316)
at com.clarkparsia.empire.impl.EntityManagerImpl.find(EntityManagerImpl.java:650)
at main.Main.find(Unknown Source)
... 2 more
Caused by: java.lang.RuntimeException: Error converting a list value.
at com.clarkparsia.empire.annotation.RdfGenerator$ToObjectFunction.apply(RdfGenerator.java:983)
... 6 more

To fix this problem I have just change a method usage at line 200 in InstanceGenerator.java :

Turn : aResult = (Class) aClass.toClass();

On : aResult = (Class) aClass.toClass(theInterface.getClassLoader(), theInterface.getProtectionDomain());

This allow javassist to reach the good ClassLoader