SpringSource/spring-data-neo4j — pull request #110 by spaetzold (2013-06-03 13:32:17+00:00)
Title: Type safety with find methods

Hi there,

I've implemented a type safety policy to allow type safe usage of repositories' find methods (second try to ease merging). I had the problem in my code base that I sometimes have an ID, but I'm not sure about the Java type of the associated entity. Loading an entity with a given ID works if the ID is somewhere in the database, but no error is raised if the the type does not match (i.e. a organisation can perfectly loaded as person).

See http://stackoverflow.com/questions/13363607/resolving-entities-with-spring-data-neo4j-returns-wrong-entity-types/13375463#13375463 for a discussion concerning this.

I've implemented a TypeSafetyPolicy class with three default implementations. These represent three levels of type safety:

*NONE*: No type safety is enforced on repository level. Thus the behaviour is the same as in past release. This is the default if the user selects no other policy.
*RETURNS_NULL*: If an entity with a given ID is loaded, but is from a different type as requested null is returned.
*THROWS_EXCEPTION*: If an entity with a given ID is loaded, but is from a different type as requested a InvalidEntityTypeException is thrown.

The policy can be selected by defining a Spring bean which is then autowired in the Neo config. Examples:

*RETURNS_NULL*:
```XML

RETURNS_NULL

```

*THROWS_EXCEPTION*:
```XML

THROWS_EXCEPTION

```

In addition to the previous attempt, more edge cases should be tested in the provided unit tests.

I hope you find this patch useful and up for merging.

-Sebastian