Empire returns class passed into EntityManager even if object is not of that type.

瀏覽次數:24 次
跳到第一則未讀訊息

Steve M

未讀,
2016年3月16日 下午2:54:382016/3/16
收件者:Empire

I have two entities being stored in Stardog and managed by Empire, they are Cat and Dog.

I have a webservice that updates the name of a Dog, if this webservice is given the Id of a Cat Empire returns a Dog object and I end up with an object that is both a Cat and a Dog.

 

For example:

My triple store has the following

            Subject                                                   Predicate                                                                Object

            http://www.domain.com/pets#1         rdf:type                                                                    http://www.domain.com/pets#Cat

            http://www.domain.com/pets#1         http://www.domain.com/pets#hasName         Frank

 

I call the webservice to update a Dog with id "http://www.domain.com/pets#1" and a new name "Mark"

 

Empire returns a Dog even though the datastore says its type is Cat. The returned Dog object will have a name populated because Empire will map any properties that are on Dog (both my Dog and Cat class have a "name" property).

            Dog dog = entityManager.find(Dog.class, entityUri);

 

Then the service updates the name and persist it.

            dog.setName(updatedName);

            entityManager.merge(dog);

 

The datastore now has two types for this entity Cat and Dog.

            Subject                                                   Predicate                                                                Object

            http://www.domain.com/pets#1         rdf:type                                                                    http://www.domain.com/pets#Cat

            http://www.domain.com/pets#1         rdf:type                                                                    http://www.domain.com/pets#Dog

            http://www.domain.com/pets#1         http://www.domain.com/pets#hasName         Mark

 

Is there a way for the EntityManager to return null or throw an exception if the id does not have the same type as what is passed in?

I could run a sparql query first to check that the id is of the type I’m trying to get back but I feel like it’s something the EntityManager should take care of.

Michael Grove

未讀,
2016年3月16日 下午3:03:022016/3/16
收件者:empir...@googlegroups.com
No, this is by design to allow for the fact that the underlying RDF schema is flexible and there's not a reason why any given IRI couldn't be of any type.
 

I could run a sparql query first to check that the id is of the type I’m trying to get back but I feel like it’s something the EntityManager should take care of.


It would be pretty trivial to add some sort of strict mode to enforce the constraint.

Cheers,

Mike
 

--
You received this message because you are subscribed to the Google Groups "Empire" group.
To unsubscribe from this group and stop receiving emails from it, send an email to empire-rdf+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

回覆所有人
回覆作者
轉寄
0 則新訊息