cancel
Showing results for 
Search instead for 
Did you mean: 

Inheritance in SDN6

damienthewave
Node Link

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

gerrit_meier
Neo4j
Neo4j

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.

damienthewave
Node Link

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(...)
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.