cyberborean / rdfbeans

Java persistence with RDF
Other
11 stars 12 forks source link

Anonymous RDFBeans by menas of interfaces #33

Open twallmey opened 5 years ago

twallmey commented 5 years ago

Hi all,

I'm using RDFBeans (annotated interfaces) with success and would like to make use of anonymous/blank nodes now. I've followed every step from the documentation, but everytime I'm trying to assign an anonymous bean to another bean (calling setter of property) it throws an exception saying, that @RDFSubject annotation is missing. My code is:

KT aBean = this.manager.create(ID_UNKNOWN, beanType); aBean.setId(null); //reset to make anonymous - id not set bBean.setProp(aBean); //throws exception

I've tried a second way to solve my problem. This time I've explictely created an anonymous node and tried to create the bean afterwards:

Resource r = SimpleValueFactory.getInstance().createBNode();
Context ctx = this.manager.create(r, Context.class);

Unfortunately, this appraoch resulted in a different exception: java.lang.ClassCastException: org.eclipse.rdf4j.model.impl.SimpleBNode cannot be cast to org.eclipse.rdf4j.model.IRI

As none of my solutions work I'm guessing that anonymous RDFBeans only work for classes and not for interfaces. Is that right? Or could someone tell me what I am doing wrong and point me into the correct direction?

Thanks in advance,

Thorben

cyberborean commented 5 years ago

Hi,

Yes, using RDFBean classes, it is possible to instantiate a bean without @RDFSubject value and assign it to properties of other beans. The anonymous bean will be represented as a BNode in the RDF model.

Instantiating a proxy object for a RDFBean interface requires an explicit resource identifier, so it doesn't work this way.

Perhaps, it makes sense to change the type of the create() argument from Resource to IRI, to make this explicit and avoid confusion.

twallmey commented 5 years ago

Hi,

thanks a lot for your response!

Wouldn't it make sense to fix this "problem" instead of changing the method signature? If creating an anonymous bean from class already works it shouldn't be a big issue to make this working for interfaces as well: an anonymous RDFBean (mapped by class) should already be assigned a generated ID that could be assigend to a RDFBean (mapped by interface) as well. From my point of view this should already solve the problem, shouldn't it?

twallmey commented 5 years ago

Are there any news about this issue?