0

I was reading this great tutorial https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-app-part-1/

I have an entity "User" which I don't need a table for in the db, the User info will be retrieved from an API. The user has a relationship with an entity that has a db table "Role".

How can I use spring boot hibernate to build such a case:

public Class User{
    private Long id;
    .
    .
    .
    @ManyToMany
    Set<Role> roles;
}
1
  • you cannot map a relationship with an nonexistent entity in the database. if you are looking for user information from other side then database can't recognize user entity as part of its objects. Commented Dec 14, 2018 at 15:47

2 Answers 2

1

I think you cannot make relations with a non managed entity, but you can write a service manually, and load the user and the roles for it separately (the user is a REST request, and the role is a query)

Sign up to request clarification or add additional context in comments.

Comments

0

I believe you will need a Service (and Repository), which will retrieve, from the DB, the Roles associated with User & then populate them in the User.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.