[DATAGRAPH-300] findOne() method behaviour Created: 24/Sep/12  Updated: 02/Sep/13  Resolved: 02/Sep/13

Status: Resolved
Project: Spring Data Neo4j
Component/s: CORE
Affects Version/s: 2.1.M1
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Nikolaos Papadakis Assignee: Michael Hunger
Resolution: Complete Votes: 1
Labels: feature-support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

kubuntu 12.04 64bit

Last updater: Trevor Marshall


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.
More specifically it returns a user objecthaving all its fields filled with null.

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).
It was differently before but we decided to go for this more schema-free friendly version.

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

Generated at Mon Jul 06 00:33:23 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.