Fahad Alsuwailih
Fahad Alsuwailih

Reputation: 1

Spring boot entity without persisting or db table

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;
}

Upvotes: 0

Views: 1692

Answers (2)

aBnormaLz
aBnormaLz

Reputation: 847

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)

Upvotes: 1

Jamie Bisotti
Jamie Bisotti

Reputation: 2685

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.

Upvotes: 0

Related Questions