Spring MongoDB data - model classes without annotations

This question relates to Spring Data MongoDB model classes without annotations.

I have a situation where I need to store domain classes in RDBMS repository or in NoSQL repository. Say, for example, my domain classes are User, Feature, PaymentRequest, Order, OrderLine, OrderHeader, etc.

I cannot use any annotations for my domain classes for various reasons.

The application team will indicate in which persistent storage they like to store. They can configure persistence in MongoDB or MySQL or in Oracle, etc.

My requirement is when I store in MongoDB using spring -data-mongodb I want to use DBRef for related objects in a domain object.

How can I achieve with spring-data-mongodb without using annotations in my model classes.

class Role { String id; String roleName; } class User { String id; String firstName; String lastName; List<Role> userRoles; } 

When I save a User object, I want to make sure that MongoDB Role objects are stored as DBRefs instead of the actual object graph.

My question is ─ without using annotations in my User and Role classes ─ How can I achieve this?

I searched for user forums and couldn't find a way. That is why I post my question here.

Thanks, Kishore Veleti AVK

+6
source share

Source: https://habr.com/ru/post/984741/


All Articles