[DATAGRAPH-300] findOne() method behaviour Created: 24/Sep/12 Updated: 02/Sep/13 Resolved: 02/Sep/13
|Project:||Spring Data Neo4j|
|Reporter:||Nikolaos Papadakis||Assignee:||Michael Hunger|
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
kubuntu 12.04 64bit
When I use: User user = template.findOne(id,User.class)
if a an id is provided that doesn't belong to a node representing a user but a to a different class (e.g car) the method returns a not null result.
Shouldn't this throw a casting error ? (form car to user?).
Both User and Car nodes have a property named _type_ (with values my.domain.User and my.domain.Car respectively)
|Comment by Michael Hunger [ 10/Oct/12 ]|
This behavior is currently "as designed" entities are silently converted into the requested type which is a valid operation (a node can hold multiple roles).
|Comment by Simon [ 18/Jul/13 ]|
I think a configurable strategy (Exception/Silent) for this case on the Repository level when the stored type doesnt match would be nice. Since the entity is casted to your repository entity class i dont see why i want a different node object there (only interesting for type hierarchies)
|Comment by Michael Hunger [ 02/Sep/13 ]|
Such a strategy is now in place, you can set a TypeSafetyPolicy with Options: NONE, RETURNS_NULL, THROWS_EXCEPTION