[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
Environment:

kubuntu 12.04 64bit


Last updater: Trevor Marshall

 Description   

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)



 Comments   
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 Sun Dec 08 05:58:43 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.