cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Inheritance in SDN6

Hi,
I have a small inheritance problem in Spring Data Neo4j 6.1.4.

Notification is an abstract class and RequestNotification is one of the supertypes.

interface NotificationRepository : Neo4jRepository<Notification, Long> {
   fun findByNotificationId(notificationId: Long): Notification?
}

In SDN5 I could then use the returned object and see the exact type.

...
val notification = findNotificationById(notificationId)
if(notification !is RequestNotification)
   throw IllegalArgumentException()
...

This can't be done after migrating to SDN6 anymore. I am getting the exception thrown, that means that Notification is not a subtype of RequestNotification.

In the database, the nodes have correct labels (i.e. Notification and RequestNotification.)
In the documentation, I couldn't see the answer to this.

What are my options?

2 REPLIES 2

This should work. I am expecting the notification to have another possible type because otherwise SDN would fail on creating the object if there is no concrete class available.
Could you please post your domain model?

Also note that in the section Node mapping there is a sub-section called A note on class hierarchies that might clarify things.

Thanks for answering, I had seen the mentioned subsection before, but I needed to have a fresh look at it. I solved the issue by adding the "@Node" annotation to the supertype.

These classes worked in SDN5

class Notification(...)

@Node
class RequestNotification(...)

These classes are woking now in SDN6.

@Node
class Notification(...)

@Node
class RequestNotification(...)